MCPcopy Create free account
hub / github.com/cli/cli / getBundle

Method getBundle

pkg/cmd/attestation/api/client.go:237–280  ·  view source on GitHub ↗
(url safeurl.SafeURL)

Source from the content-addressed store, hash-verified

235}
236
237func (c *LiveClient) getBundle(url safeurl.SafeURL) (*bundle.Bundle, error) {
238 c.logger.VerbosePrintf("Fetching attestation bundle with bundle URL\n\n")
239
240 var sgBundle *bundle.Bundle
241 bo := backoff.NewConstantBackOff(getAttestationRetryInterval)
242 err := backoff.Retry(func() error {
243 resp, err := c.externalHttpClient.Get(url.String())
244 if err != nil {
245 return fmt.Errorf("request to fetch bundle from URL failed: %w", err)
246 }
247
248 if resp.StatusCode >= 500 && resp.StatusCode <= 599 {
249 return fmt.Errorf("attestation bundle with URL %s returned status code %d", url.String(), resp.StatusCode)
250 }
251
252 defer resp.Body.Close()
253 body, err := io.ReadAll(resp.Body)
254 if err != nil {
255 return fmt.Errorf("failed to read blob storage response body: %w", err)
256 }
257
258 var out []byte
259 decompressed, err := snappy.Decode(out, body)
260 if err != nil {
261 return backoff.Permanent(fmt.Errorf("failed to decompress with snappy: %w", err))
262 }
263
264 var pbBundle v1.Bundle
265 if err = protojson.Unmarshal(decompressed, &pbBundle); err != nil {
266 return backoff.Permanent(fmt.Errorf("failed to unmarshal to bundle: %w", err))
267 }
268
269 c.logger.VerbosePrintf("Successfully fetched bundle\n\n")
270
271 sgBundle, err = bundle.NewBundle(&pbBundle)
272 if err != nil {
273 return backoff.Permanent(fmt.Errorf("failed to create new bundle: %w", err))
274 }
275
276 return nil
277 }, backoff.WithMaxRetries(bo, 3))
278
279 return sgBundle, err
280}
281
282func shouldRetry(err error) bool {
283 var httpError api.HTTPError

Callers 5

TestGetBundleFunction · 0.95

Calls 5

VerbosePrintfMethod · 0.80
GetMethod · 0.65
StringMethod · 0.65
ErrorfMethod · 0.65
CloseMethod · 0.65

Tested by 4

TestGetBundleFunction · 0.76