feat(store): add token lifetime limit and tokens.manage permission
The built-in Admin role gains tokens.manage. Refs #48 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
d7d4821e3e
commit
da128c5081
8 files changed
+69
-19
No files matched your search
@@ -23,6 +23,26 @@ func (q *Queries) APITokenOrg(ctx context.Context, hash []byte) (uuid.UUID, erro
|
||||
return org_id, err
|
||||
}
|
||||
|
||||
const clampAPITokenExpiry = `-- name: ClampAPITokenExpiry :execrows
|
||||
UPDATE api_tokens SET expires_at = now() + make_interval(days => $1::int)
|
||||
WHERE org_id = $2
|
||||
AND (expires_at IS NULL OR expires_at > now() + make_interval(days => $1::int))
|
||||
`
|
||||
|
||||
type ClampAPITokenExpiryParams struct {
|
||||
MaxDays int32
|
||||
OrgID uuid.UUID
|
||||
}
|
||||
|
||||
// Shortens tokens that would outlive a newly set maximum lifetime.
|
||||
func (q *Queries) ClampAPITokenExpiry(ctx context.Context, arg ClampAPITokenExpiryParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, clampAPITokenExpiry, arg.MaxDays, arg.OrgID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const createAPIToken = `-- name: CreateAPIToken :one
|
||||
INSERT INTO api_tokens (org_id, user_id, name, token_hash, prefix, permissions, expires_at)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
|
||||
Reference in new issue
Block a user