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