CreateToken generates an API key for the user ID provided with custom expiration. These tokens can be used for long-lived access, like for use with CI.
(ctx context.Context, userID string, req CreateTokenRequest)
| 64 | // custom expiration. These tokens can be used for long-lived access, |
| 65 | // like for use with CI. |
| 66 | func (c *Client) CreateToken(ctx context.Context, userID string, req CreateTokenRequest) (GenerateAPIKeyResponse, error) { |
| 67 | res, err := c.Request(ctx, http.MethodPost, fmt.Sprintf("/api/v2/users/%s/keys/tokens", userID), req) |
| 68 | if err != nil { |
| 69 | return GenerateAPIKeyResponse{}, err |
| 70 | } |
| 71 | defer res.Body.Close() |
| 72 | if res.StatusCode > http.StatusCreated { |
| 73 | return GenerateAPIKeyResponse{}, ReadBodyAsError(res) |
| 74 | } |
| 75 | |
| 76 | var apiKey GenerateAPIKeyResponse |
| 77 | return apiKey, json.NewDecoder(res.Body).Decode(&apiKey) |
| 78 | } |
| 79 | |
| 80 | // CreateAPIKey generates an API key for the user ID provided. |
| 81 | // CreateToken should be used over CreateAPIKey. CreateToken allows better |