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