feat: add permanent deletion for revoked keys
DELETE /admin/api/keys/{id}/purge removes the key record; it requires the key to be revoked first and keeps historical logs. The keys page swaps the revoke button for a delete button once a key is revoked.
This commit is contained in:
@@ -203,6 +203,27 @@ func (s *Server) keys(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
func (s *Server) keyID(w http.ResponseWriter, r *http.Request) {
|
||||
id := strings.TrimPrefix(r.URL.Path, "/admin/api/keys/")
|
||||
if purgeID, ok := strings.CutSuffix(id, "/purge"); ok {
|
||||
if r.Method != "DELETE" {
|
||||
errJSON(w, 405, "method not allowed")
|
||||
return
|
||||
}
|
||||
var revoked bool
|
||||
if e := s.db.QueryRow("SELECT revoked FROM keys WHERE id=?", purgeID).Scan(&revoked); e == sql.ErrNoRows {
|
||||
errJSON(w, 404, "not found")
|
||||
return
|
||||
} else if e != nil {
|
||||
errJSON(w, 500, "database error")
|
||||
return
|
||||
}
|
||||
if !revoked {
|
||||
errJSON(w, 409, "revoke the key before deleting")
|
||||
return
|
||||
}
|
||||
res, e := s.db.Exec("DELETE FROM keys WHERE id=?", purgeID)
|
||||
mutation(w, res, e)
|
||||
return
|
||||
}
|
||||
if r.Method == "DELETE" {
|
||||
res, e := s.db.Exec("UPDATE keys SET enabled=0,revoked=1 WHERE id=?", id)
|
||||
mutation(w, res, e)
|
||||
|
||||
Reference in New Issue
Block a user