(file stream.Stream, feedId string, uploadBar *visualization.ProgressBar)
| 80 | } |
| 81 | |
| 82 | func (c OrchestratorClient) Upload(file stream.Stream, feedId string, uploadBar *visualization.ProgressBar) error { |
| 83 | context, cancel := context.WithCancelCause(context.Background()) |
| 84 | request := c.createUploadRequest(file, feedId, uploadBar, cancel) |
| 85 | client := network.NewHttpClient(c.logger, c.httpClientSettings()) |
| 86 | response, err := client.SendWithContext(request, context) |
| 87 | if err != nil { |
| 88 | return err |
| 89 | } |
| 90 | defer func() { _ = response.Body.Close() }() |
| 91 | body, err := io.ReadAll(response.Body) |
| 92 | if err != nil { |
| 93 | return fmt.Errorf("Error reading response: %w", err) |
| 94 | } |
| 95 | if response.StatusCode == http.StatusConflict { |
| 96 | return ErrPackageAlreadyExists |
| 97 | } |
| 98 | if response.StatusCode != http.StatusOK { |
| 99 | return fmt.Errorf("Orchestrator returned status code '%v' and body '%v'", response.StatusCode, string(body)) |
| 100 | } |
| 101 | return nil |
| 102 | } |
| 103 | |
| 104 | func (c OrchestratorClient) createUploadRequest(file stream.Stream, feedId string, uploadBar *visualization.ProgressBar, cancel context.CancelCauseFunc) *network.HttpRequest { |
| 105 | bodyReader, bodyWriter := io.Pipe() |
no test coverage detected