| 235 | } |
| 236 | |
| 237 | func (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 | |
| 282 | func shouldRetry(err error) bool { |
| 283 | var httpError api.HTTPError |