MCPcopy Index your code
hub / github.com/NdoleStudio/httpsms / DeleteAPIKey

Method DeleteAPIKey

api/pkg/handlers/user_handler.go:256–274  ·  view source on GitHub ↗

DeleteAPIKey rotates the API Key for a user @Summary Rotate the user's API Key @Description Rotate the user's API key in case the current API Key is compromised @Security ApiKeyAuth @Tags Users @Accept json @Produce json @Param userID path string true "ID of th

(c fiber.Ctx)

Source from the content-addressed store, hash-verified

254// @Failure 500 {object} responses.InternalServerError
255// @Router /users/{userID}/api-keys [delete]
256func (h *UserHandler) DeleteAPIKey(c fiber.Ctx) error {
257 ctx, span := h.tracer.StartFromFiberCtx(c)
258 defer span.End()
259
260 ctxLogger := h.tracer.CtxLogger(h.logger, span)
261
262 if c.Params("userID") != string(h.userIDFomContext(c)) {
263 return h.responseUnauthorized(c)
264 }
265
266 user, err := h.service.RotateAPIKey(ctx, c.OriginalURL(), h.userIDFomContext(c))
267 if err != nil {
268 msg := fmt.Sprintf("cannot rotate the api key for [%T] with ID [%s]", user, h.userIDFomContext(c))
269 ctxLogger.Error(h.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)))
270 return h.responseInternalServerError(c)
271 }
272
273 return h.responseOK(c, "API Key rotated successfully", user)
274}
275
276// subscriptionPayments returns the last 10 payments of the currently authenticated user
277// @Summary Get the last 10 subscription payments.

Callers

nothing calls this directly

Calls 9

userIDFomContextMethod · 0.80
responseUnauthorizedMethod · 0.80
responseOKMethod · 0.80
StartFromFiberCtxMethod · 0.65
CtxLoggerMethod · 0.65
RotateAPIKeyMethod · 0.65
ErrorMethod · 0.65
WrapErrorSpanMethod · 0.65

Tested by

no test coverage detected