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