MCPcopy
hub / github.com/mudler/LocalAI / RevokeAPIKey

Function RevokeAPIKey

core/http/auth/apikeys.go:110–116  ·  view source on GitHub ↗

RevokeAPIKey deletes an API key. Only the owner can revoke their own key.

(db *gorm.DB, keyID, userID string)

Source from the content-addressed store, hash-verified

108
109// RevokeAPIKey deletes an API key. Only the owner can revoke their own key.
110func RevokeAPIKey(db *gorm.DB, keyID, userID string) error {
111 result := db.Where("id = ? AND user_id = ?", keyID, userID).Delete(&UserAPIKey{})
112 if result.RowsAffected == 0 {
113 return fmt.Errorf("API key not found or not owned by user")
114 }
115 return result.Error
116}
117
118// CleanExpiredAPIKeys removes all API keys that have passed their expiry time.
119func CleanExpiredAPIKeys(db *gorm.DB) error {

Callers 4

middleware_test.goFile · 0.92
apikeys_test.goFile · 0.92
RegisterAuthRoutesFunction · 0.92
newTestAuthAppFunction · 0.92

Calls 1

DeleteMethod · 0.65

Tested by 1

newTestAuthAppFunction · 0.74