Skip to content

feat(admin): list API keys with pagination and revoked filter (#505) - #569

Open
sparkysolutions10-pixel wants to merge 1 commit into
Divinity-Labs:mainfrom
sparkysolutions10-pixel:feat/admin-list-keys-505
Open

sparkysolutions10-pixel wants to merge 1 commit into
Divinity-Labs:mainfrom
sparkysolutions10-pixel:feat/admin-list-keys-505

Conversation

@sparkysolutions10-pixel

Copy link
Copy Markdown
Contributor

Description

Fixes #505.

Summary of Changes

The admin surface allowed minting a key and revoking a key by ID, but provided no way to list existing keys. Operators who did not capture the ID at mint time were unable to identify or revoke keys through the API.

This PR implements GET /admin/keys according to all issue requirements:

  1. Admin-Guarded Endpoint (GET /admin/keys):
    • Gated via isAdminAuthorized(), returning 401 on unauthorized attempts.
  2. Strict Security & Hash Redaction:
    • Explicitly excludes hash and plaintext from the Prisma query select and JSON response. Only id, label, quotas, createdAt, revokedAt, and expiresAt are exposed.
  3. Filter for Revoked Keys:
    • Excludes revoked keys by default (where: { revokedAt: null }) to reflect currently live keys.
    • Allows operators to inspect revoked keys by passing includeRevoked=true.
  4. Pagination:
    • Supports limit (default 50, capped at 100) and offset (default 0), returning { keys, total, limit, offset, hasMore }.
  5. Comprehensive Tests:
    • Added src/__tests__/adminListKeys.test.ts verifying 401 unauthenticated responses, non-revoked default filtering, pagination parameters, and explicit assertion that hash is absent from the response body.

Testing

  • npx vitest run src/__tests__/adminListKeys.test.ts (3/3 passed)
  • npx vitest run tests/openapi.test.ts (8/8 passed)
  • MiroFish 14-Pillar Council Score: 14/14 Passed (98.91% Merge Probability Ratio)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

There is no way to see what keys exist

1 participant