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

Method apiKeyByID

coderd/apikey.go:248–266  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

246// @Success 200 {object} codersdk.APIKey
247// @Router /api/v2/users/{user}/keys/{keyid} [get]
248func (api *API) apiKeyByID(rw http.ResponseWriter, r *http.Request) {
249 ctx := r.Context()
250
251 keyID := chi.URLParam(r, "keyid")
252 key, err := api.Database.GetAPIKeyByID(ctx, keyID)
253 if httpapi.Is404Error(err) {
254 httpapi.ResourceNotFound(rw)
255 return
256 }
257 if err != nil {
258 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
259 Message: "Internal error fetching API key.",
260 Detail: err.Error(),
261 })
262 return
263 }
264
265 httpapi.Write(ctx, rw, http.StatusOK, convertAPIKey(key))
266}
267
268// @Summary Get API key by token name
269// @ID get-api-key-by-token-name

Callers

nothing calls this directly

Calls 7

Is404ErrorFunction · 0.92
ResourceNotFoundFunction · 0.92
WriteFunction · 0.92
convertAPIKeyFunction · 0.85
ContextMethod · 0.65
GetAPIKeyByIDMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected