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

Method getBundle

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

Source from the content-addressed store, hash-verified

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