MCPcopy Index your code
hub / github.com/coder/coder / CreateAPIKey

Method CreateAPIKey

codersdk/apikey.go:85–97  ·  view source on GitHub ↗

CreateAPIKey generates an API key for the user ID provided. CreateToken should be used over CreateAPIKey. CreateToken allows better tracking of the token's usage and allows for custom expiration. Only use CreateAPIKey if you want to emulate the session created for a browser like login.

(ctx context.Context, user string)

Source from the content-addressed store, hash-verified

83// Only use CreateAPIKey if you want to emulate the session created for
84// a browser like login.
85func (c *Client) CreateAPIKey(ctx context.Context, user string) (GenerateAPIKeyResponse, error) {
86 res, err := c.Request(ctx, http.MethodPost, fmt.Sprintf("/api/v2/users/%s/keys", user), nil)
87 if err != nil {
88 return GenerateAPIKeyResponse{}, err
89 }
90 defer res.Body.Close()
91 if res.StatusCode > http.StatusCreated {
92 return GenerateAPIKeyResponse{}, ReadBodyAsError(res)
93 }
94
95 var apiKey GenerateAPIKeyResponse
96 return apiKey, json.NewDecoder(res.Body).Decode(&apiKey)
97}
98
99type TokensFilter struct {
100 IncludeAll bool `json:"include_all"`

Callers 6

TestAPIKey_OKFunction · 0.80
TestAPIKey_DeletedFunction · 0.80
TestAPIKey_SetDefaultFunction · 0.80
loginMethod · 0.80
openVSCodeMethod · 0.80

Calls 3

RequestMethod · 0.95
ReadBodyAsErrorFunction · 0.85
CloseMethod · 0.65

Tested by 4

TestAPIKey_OKFunction · 0.64
TestAPIKey_DeletedFunction · 0.64
TestAPIKey_SetDefaultFunction · 0.64