mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat(coderd/database): add AI Gateway key auth lookup and last-used queries (#26505)
Adds DB methods`GetAIGatewayKeyIDByHashedSecret` and `UpdateAIGatewayKeyLastUsedAt`. `GetAIGatewayKeyIDByHashedSecret` - returns AI Gateway key ID by hashed secret value. `UpdateAIGatewayKeyLastUsedAt` - updates last used timestamp for given AI Gateway key. Used by standalone AI Gateway for authentication and keeping track of currently used keys.
This commit is contained in:
@@ -11,3 +11,19 @@ ORDER BY created_at ASC;
|
||||
-- name: DeleteAIGatewayKey :one
|
||||
DELETE FROM ai_gateway_keys WHERE id = $1
|
||||
RETURNING id, name, secret_prefix, created_at, last_used_at;
|
||||
|
||||
-- name: GetAIGatewayKeyByHashedSecret :one
|
||||
-- Authenticates a standalone AI Gateway replica by its hashed key secret,
|
||||
-- returning the matched key. The lookup is an exact match on a unique index,
|
||||
-- so a returned row is itself proof the secret is valid.
|
||||
SELECT *
|
||||
FROM ai_gateway_keys
|
||||
WHERE hashed_secret = $1;
|
||||
|
||||
-- name: UpdateAIGatewayKeyLastUsedAt :execrows
|
||||
-- Records liveness for an active Gateway DRPC session. The database sets the
|
||||
-- timestamp so it stays consistent regardless of clock drift between API
|
||||
-- replicas.
|
||||
UPDATE ai_gateway_keys
|
||||
SET last_used_at = NOW()
|
||||
WHERE id = $1;
|
||||
|
||||
Reference in New Issue
Block a user