-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from replicatedhq/upload
Upload results
- Loading branch information
Showing
5 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package cli | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"net/http" | ||
|
||
analyzerunner "github.com/replicatedhq/troubleshoot/pkg/analyze" | ||
) | ||
|
||
type UploadPreflightResult struct { | ||
IsFail bool `json:"isFail,omitempty"` | ||
IsWarn bool `json:"isWarn,omitempty"` | ||
IsPass bool `json:"isPass,omitempty"` | ||
|
||
Title string `json:"title"` | ||
Message string `json:"message"` | ||
URI string `json:"uri,omitempty"` | ||
} | ||
|
||
type UploadPreflightResults struct { | ||
Results []*UploadPreflightResult `json:"results"` | ||
} | ||
|
||
func tryUploadResults(uri string, preflightName string, analyzeResults []*analyzerunner.AnalyzeResult) error { | ||
uploadPreflightResults := UploadPreflightResults{ | ||
Results: []*UploadPreflightResult{}, | ||
} | ||
for _, analyzeResult := range analyzeResults { | ||
uploadPreflightResult := &UploadPreflightResult{ | ||
IsFail: analyzeResult.IsFail, | ||
IsWarn: analyzeResult.IsWarn, | ||
IsPass: analyzeResult.IsPass, | ||
Title: analyzeResult.Title, | ||
Message: analyzeResult.Message, | ||
URI: analyzeResult.URI, | ||
} | ||
|
||
uploadPreflightResults.Results = append(uploadPreflightResults.Results, uploadPreflightResult) | ||
} | ||
|
||
b, err := json.Marshal(uploadPreflightResults) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
req, err := http.NewRequest("POST", uri, bytes.NewBuffer(b)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
req.Header.Set("Content-Type", "application/json") | ||
|
||
client := http.DefaultClient | ||
resp, err := client.Do(req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if resp.StatusCode > 290 { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters