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

Method fetchBundleFromAttestations

pkg/cmd/attestation/api/client.go:199–235  ·  view source on GitHub ↗
(attestations []*Attestation)

Source from the content-addressed store, hash-verified

197}
198
199func (c *LiveClient) fetchBundleFromAttestations(attestations []*Attestation) ([]*Attestation, error) {
200 fetched := make([]*Attestation, len(attestations))
201 g := errgroup.Group{}
202 for i, a := range attestations {
203 g.Go(func() error {
204 if a.Bundle == nil && a.BundleURL == "" {
205 return fmt.Errorf("attestation has no bundle or bundle URL")
206 }
207
208 // for now, we fall back to the bundle field if the bundle URL is empty
209 if a.BundleURL == "" {
210 c.logger.VerbosePrintf("Bundle URL is empty. Falling back to bundle field\n\n")
211 fetched[i] = &Attestation{
212 Bundle: a.Bundle,
213 }
214 return nil
215 }
216
217 // otherwise fetch the bundle with the provided URL
218 b, err := c.getBundle(safeurl.NewImmutableSafeURL(a.BundleURL))
219 if err != nil {
220 return fmt.Errorf("failed to fetch bundle with URL: %w", err)
221 }
222 fetched[i] = &Attestation{
223 Bundle: b,
224 }
225
226 return nil
227 })
228 }
229
230 if err := g.Wait(); err != nil {
231 return nil, err
232 }
233
234 return fetched, nil
235}
236
237func (c *LiveClient) getBundle(url safeurl.SafeURL) (*bundle.Bundle, error) {
238 c.logger.VerbosePrintf("Fetching attestation bundle with bundle URL\n\n")

Calls 5

getBundleMethod · 0.95
NewImmutableSafeURLFunction · 0.92
VerbosePrintfMethod · 0.80
ErrorfMethod · 0.65
WaitMethod · 0.65