RevokeAPIKey revokes an API key Parameters: - c: The Gin context containing the request and response Responses: - 204 No Content: If the API key is successfully revoked - 404 Not Found: If the API key is not found - 403 Forbidden: If the user doesn't own the API key
(c *gin.Context)
| 66 | // - 404 Not Found: If the API key is not found |
| 67 | // - 403 Forbidden: If the user doesn't own the API key |
| 68 | func (a Api) RevokeAPIKey(c *gin.Context) { |
| 69 | id := c.Param("id") |
| 70 | owner := c.Query("owner") |
| 71 | if owner == "" { |
| 72 | c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"}) |
| 73 | return |
| 74 | } |
| 75 | |
| 76 | if err := a.ledgerforge.RevokeAPIKey(c.Request.Context(), id, owner); err != nil { |
| 77 | switch err { |
| 78 | case database.ErrAPIKeyNotFound: |
| 79 | c.JSON(http.StatusNotFound, gin.H{"error": "API key not found"}) |
| 80 | case database.ErrInvalidAPIKey: |
| 81 | c.JSON(http.StatusForbidden, gin.H{"error": "unauthorized"}) |
| 82 | default: |
| 83 | c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) |
| 84 | } |
| 85 | return |
| 86 | } |
| 87 | |
| 88 | c.Status(http.StatusNoContent) |
| 89 | } |
nothing calls this directly
no test coverage detected