MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / CreateAPIKey

Method CreateAPIKey

api/apikeys.go:19–33  ·  view source on GitHub ↗

CreateAPIKey creates a new API key for the authenticated user Parameters: - c: The Gin context containing the request and response Responses: - 400 Bad Request: If there's an error in the request body - 201 Created: If the API key is successfully created

(c *gin.Context)

Source from the content-addressed store, hash-verified

17// - 400 Bad Request: If there's an error in the request body
18// - 201 Created: If the API key is successfully created
19func (a Api) CreateAPIKey(c *gin.Context) {
20 var req model.CreateAPIKeyRequest
21 if err := c.ShouldBindJSON(&req); err != nil {
22 c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
23 return
24 }
25
26 apiKey, err := a.ledgerforge.CreateAPIKey(c.Request.Context(), req.Name, req.Owner, req.Scopes, req.ExpiresAt)
27 if err != nil {
28 c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
29 return
30 }
31
32 c.JSON(http.StatusCreated, apiKey)
33}
34
35// ListAPIKeys lists all API keys for the authenticated user
36//

Callers

nothing calls this directly

Calls 2

CreateAPIKeyMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected