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

Method getAttestations

pkg/cmd/attestation/api/client.go:142–197  ·  view source on GitHub ↗
(params FetchParams)

Source from the content-addressed store, hash-verified

140}
141
142func (c *LiveClient) getAttestations(params FetchParams) ([]*Attestation, error) {
143 u, err := c.buildRequestURL(params)
144 if err != nil {
145 return nil, err
146 }
147
148 var attestations []*Attestation
149 var resp AttestationsResponse
150 bo := backoff.NewConstantBackOff(getAttestationRetryInterval)
151
152 var pageURL safeurl.SafeURL = u
153
154 // if no attestation or less than limit, then keep fetching
155 for pageURL.String() != "" && len(attestations) < params.Limit {
156 err := backoff.Retry(func() error {
157 newURL, restErr := c.githubAPI.RESTWithNext(c.host, http.MethodGet, pageURL.String(), nil, &resp)
158 if restErr != nil {
159 if shouldRetry(restErr) {
160 return restErr
161 }
162 return backoff.Permanent(restErr)
163 }
164
165 pageURL = safeurl.NewImmutableSafeURL(newURL)
166
167 // filter by the initiator type
168 if params.Initiator != "" {
169 filtered := make([]*Attestation, 0, len(resp.Attestations))
170 for _, att := range resp.Attestations {
171 if att.Initiator == params.Initiator {
172 filtered = append(filtered, att)
173 }
174 }
175 resp.Attestations = filtered
176 }
177 attestations = append(attestations, resp.Attestations...)
178
179 return nil
180 }, backoff.WithMaxRetries(bo, 3))
181
182 // bail if RESTWithNext errored out
183 if err != nil {
184 return nil, err
185 }
186 }
187
188 if len(attestations) == 0 {
189 return nil, ErrNoAttestationsFound
190 }
191
192 if len(attestations) > params.Limit {
193 return attestations[:params.Limit], nil
194 }
195
196 return attestations, nil
197}
198
199func (c *LiveClient) fetchBundleFromAttestations(attestations []*Attestation) ([]*Attestation, error) {

Callers 2

GetByDigestMethod · 0.95

Calls 5

buildRequestURLMethod · 0.95
StringMethod · 0.95
NewImmutableSafeURLFunction · 0.92
shouldRetryFunction · 0.70
RESTWithNextMethod · 0.65