| 13 | ) |
| 14 | |
| 15 | func httpsGet(ctx context.Context, url string) (string, error) { |
| 16 | log := zerolog.Ctx(ctx) |
| 17 | //nolint: gosec |
| 18 | response, err := http.Get(url) |
| 19 | if err != nil { |
| 20 | log.Err(err).Msg("failed to download file") |
| 21 | return "", fmt.Errorf("downloading file: %w", err) |
| 22 | } |
| 23 | defer response.Body.Close() |
| 24 | body, err := io.ReadAll(response.Body) |
| 25 | if err != nil { |
| 26 | log.Err(err).Msg("failed to read response body") |
| 27 | return "", fmt.Errorf("reading response body: %w", err) |
| 28 | } |
| 29 | if response.StatusCode != 200 { |
| 30 | log.Debug().Int("status-code", response.StatusCode).Msg("got non-200 response when downloading file. Logging response body:") |
| 31 | log.Debug().Msg(string(body)) |
| 32 | return "", fmt.Errorf("got http code %d: %w", response.StatusCode, errBadHTTPStatus) |
| 33 | } |
| 34 | return string(body), nil |
| 35 | } |
| 36 | |
| 37 | func download(ctx context.Context, url string) (string, error) { |
| 38 | if strings.HasPrefix(url, "file://") { |