func()

in ci/internal/mitre/client.go [184:213]


func (r *Client) do(ctx context.Context, method, path string, body []byte) (*http.Response, error) {
	if r.dryrun && method != http.MethodGet {
		slog.Warn("DRY RUN: skipping MITRE API request", "method", method, "path", path)
		return nil, nil
	}

	u := fmt.Sprintf("%s/%s", r.baseURL, path)

	req, err := retryablehttp.NewRequestWithContext(ctx, method, u, body)
	if err != nil {
		return nil, fmt.Errorf("creating %s %s request: %w", method, path, err)
	}

	req.Header.Add("CVE-API-ORG", r.cnaShortname)
	req.Header.Add("CVE-API-USER", r.apiUser)
	req.Header.Add("CVE-API-KEY", r.apiKey)
	req.Header.Add("Content-Type", "application/json")

	resp, err := r.client.Do(req)
	if err != nil {
		return nil, fmt.Errorf("performing %s %s request: %w", method, path, err)
	}

	if resp.StatusCode < 200 || resp.StatusCode > 299 {
		resp.Body.Close()
		return nil, fmt.Errorf("unexpected response status for %s %s request: %s", method, path, resp.Status)
	}

	return resp, nil
}