Tokens list machine API keys.
(ctx context.Context, userID string, filter TokensFilter)
| 123 | |
| 124 | // Tokens list machine API keys. |
| 125 | func (c *Client) Tokens(ctx context.Context, userID string, filter TokensFilter) ([]APIKeyWithOwner, error) { |
| 126 | res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/users/%s/keys/tokens", userID), nil, filter.asRequestOption()) |
| 127 | if err != nil { |
| 128 | return nil, err |
| 129 | } |
| 130 | defer res.Body.Close() |
| 131 | if res.StatusCode > http.StatusOK { |
| 132 | return nil, ReadBodyAsError(res) |
| 133 | } |
| 134 | apiKey := []APIKeyWithOwner{} |
| 135 | return apiKey, json.NewDecoder(res.Body).Decode(&apiKey) |
| 136 | } |
| 137 | |
| 138 | // APIKeyByID returns the api key by id. |
| 139 | func (c *Client) APIKeyByID(ctx context.Context, userID string, id string) (*APIKey, error) { |