(ctx context.Context)
| 25 | ) |
| 26 | |
| 27 | func (r *Runner) ListCredentials(ctx context.Context) ([]params.ForgeCredentials, error) { |
| 28 | if !auth.IsAdmin(ctx) { |
| 29 | return nil, runnerErrors.ErrUnauthorized |
| 30 | } |
| 31 | |
| 32 | // Get the credentials from the store. The cache is always updated after the database successfully |
| 33 | // commits the transaction that created/updated the credentials. |
| 34 | // If we create a set of credentials then immediately after we call ListCredentials, |
| 35 | // there is a posibillity that not all creds will be in the cache. |
| 36 | creds, err := r.store.ListGithubCredentials(ctx) |
| 37 | if err != nil { |
| 38 | return nil, fmt.Errorf("error fetching github credentials: %w", err) |
| 39 | } |
| 40 | |
| 41 | // If we do have cache, update the rate limit for each credential. The rate limits are queried |
| 42 | // every 30 seconds and set in cache. |
| 43 | credsCache := cache.GetAllGithubCredentialsAsMap() |
| 44 | for idx, cred := range creds { |
| 45 | inCache, ok := credsCache[cred.ID] |
| 46 | if ok { |
| 47 | creds[idx].RateLimit = inCache.RateLimit |
| 48 | } |
| 49 | } |
| 50 | return creds, nil |
| 51 | } |
| 52 | |
| 53 | func (r *Runner) CreateGithubCredentials(ctx context.Context, param params.CreateGithubCredentialsParams) (params.ForgeCredentials, error) { |
| 54 | if !auth.IsAdmin(ctx) { |
nothing calls this directly
no test coverage detected