MCPcopy
hub / github.com/autobrr/qui / ValidateAPIKey

Method ValidateAPIKey

internal/models/api_key.go:267–284  ·  view source on GitHub ↗

ValidateAPIKey validates a raw API key and returns the associated APIKey if valid

(ctx context.Context, rawKey string)

Source from the content-addressed store, hash-verified

265
266// ValidateAPIKey validates a raw API key and returns the associated APIKey if valid
267func (s *APIKeyStore) ValidateAPIKey(ctx context.Context, rawKey string) (*APIKey, error) {
268 keyHash := HashAPIKey(rawKey)
269
270 apiKey, err := s.GetByHash(ctx, keyHash)
271 if err != nil {
272 if errors.Is(err, ErrAPIKeyNotFound) {
273 return nil, ErrInvalidAPIKey
274 }
275 return nil, err
276 }
277
278 // Update last used timestamp asynchronously
279 go func() {
280 _ = s.UpdateLastUsed(ctx, apiKey.ID)
281 }()
282
283 return apiKey, nil
284}

Callers

nothing calls this directly

Calls 4

GetByHashMethod · 0.95
UpdateLastUsedMethod · 0.95
HashAPIKeyFunction · 0.85
IsMethod · 0.45

Tested by

no test coverage detected