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

Method APIKeyByName

codersdk/apikey.go:153–164  ·  view source on GitHub ↗

APIKeyByName returns the api key by name.

(ctx context.Context, userID string, name string)

Source from the content-addressed store, hash-verified

151
152// APIKeyByName returns the api key by name.
153func (c *Client) APIKeyByName(ctx context.Context, userID string, name string) (*APIKey, error) {
154 res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/users/%s/keys/tokens/%s", userID, name), nil)
155 if err != nil {
156 return nil, err
157 }
158 defer res.Body.Close()
159 if res.StatusCode > http.StatusCreated {
160 return nil, ReadBodyAsError(res)
161 }
162 apiKey := &APIKey{}
163 return apiKey, json.NewDecoder(res.Body).Decode(apiKey)
164}
165
166// DeleteAPIKey deletes API key by id.
167func (c *Client) DeleteAPIKey(ctx context.Context, userID string, id string) error {

Callers 3

TestTokensFunction · 0.80
viewTokenMethod · 0.80
removeTokenMethod · 0.80

Calls 3

RequestMethod · 0.95
ReadBodyAsErrorFunction · 0.85
CloseMethod · 0.65

Tested by 1

TestTokensFunction · 0.64