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

Method fetchBundleFromAttestations

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

Source from the content-addressed store, hash-verified

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