HandleDeleteAPIKey deletes an API key owned by the authenticated user.
(w http.ResponseWriter, r *http.Request)
| 842 | |
| 843 | // HandleDeleteAPIKey deletes an API key owned by the authenticated user. |
| 844 | func (ua *UserAuth) HandleDeleteAPIKey(w http.ResponseWriter, r *http.Request) { |
| 845 | user := ua.AuthenticateRequest(r) |
| 846 | if user == nil { |
| 847 | http.Error(w, "not authenticated", http.StatusUnauthorized) |
| 848 | return |
| 849 | } |
| 850 | |
| 851 | path := strings.TrimPrefix(r.URL.Path, "/api/keys/") |
| 852 | keyID := path |
| 853 | if keyID == "" { |
| 854 | http.Error(w, "key id required", http.StatusBadRequest) |
| 855 | return |
| 856 | } |
| 857 | |
| 858 | if err := ua.store.DeleteAPIKey(r.Context(), keyID, user.ID); err != nil { |
| 859 | http.Error(w, err.Error(), http.StatusNotFound) |
| 860 | return |
| 861 | } |
| 862 | |
| 863 | w.WriteHeader(http.StatusOK) |
| 864 | } |
nothing calls this directly
no test coverage detected