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

Method apiKeyByName

coderd/apikey.go:277–301  ·  view source on GitHub ↗

@Summary Get API key by token name @ID get-api-key-by-token-name @Security CoderSessionToken @Produce json @Tags Users @Param user path string true "User ID, name, or me" @Param keyname path string true "Key Name" format(string) @Success 200 {object} codersdk.APIKey @Router /api/v2/users/{user}/keys

(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

275// @Success 200 {object} codersdk.APIKey
276// @Router /api/v2/users/{user}/keys/tokens/{keyname} [get]
277func (api *API) apiKeyByName(rw http.ResponseWriter, r *http.Request) {
278 var (
279 ctx = r.Context()
280 user = httpmw.UserParam(r)
281 tokenName = chi.URLParam(r, "keyname")
282 )
283
284 token, err := api.Database.GetAPIKeyByName(ctx, database.GetAPIKeyByNameParams{
285 TokenName: tokenName,
286 UserID: user.ID,
287 })
288 if httpapi.Is404Error(err) {
289 httpapi.ResourceNotFound(rw)
290 return
291 }
292 if err != nil {
293 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
294 Message: "Internal error fetching API key.",
295 Detail: err.Error(),
296 })
297 return
298 }
299
300 httpapi.Write(ctx, rw, http.StatusOK, convertAPIKey(token))
301}
302
303// @Summary Get user tokens
304// @ID get-user-tokens

Callers

nothing calls this directly

Calls 8

UserParamFunction · 0.92
Is404ErrorFunction · 0.92
ResourceNotFoundFunction · 0.92
WriteFunction · 0.92
convertAPIKeyFunction · 0.85
ContextMethod · 0.65
GetAPIKeyByNameMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected