Skip to content

feat(BA-6063): add UserID type and ResolveUserIDByAccessKey action#11647

Open
fregataa wants to merge 3 commits into
mainfrom
BA-6063
Open

feat(BA-6063): add UserID type and ResolveUserIDByAccessKey action#11647
fregataa wants to merge 3 commits into
mainfrom
BA-6063

Conversation

@fregataa
Copy link
Copy Markdown
Member

@fregataa fregataa commented May 18, 2026

Summary

  • Add UserID = NewType("UserID", UUID) under common/identifier/user.py so handler/service signatures can carry the keypair owner's UUID with static-type discrimination (mirrors the existing common/identifier/vfolder.py pattern).
  • Add ResolveUserIDByAccessKeyAction on the auth service plus a backing get_user_id_by_access_key in the auth repository / db_source (selects keypairs.c.user, raises AccessKeyNotFound when missing) so any handler or service can resolve an access_key to its owning user_uuid without depending on the keypairs table directly.
  • Register the new action processor on AuthProcessors and add the spec to supported_actions(). Pure additive — no existing call site is modified.

Test plan

  • pants fmt fix lint check on the touched files (passes locally)
  • No behavior change to existing REST v1/v2, GraphQL, agent RPC, or events surfaces

Resolves BA-6063

Add a shared UserID identifier type under common/identifier/ and
introduce ResolveUserIDByAccessKey on the auth service so any
handler/service can resolve an access_key to its owning user_uuid
without depending on the keypairs table directly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 18, 2026 03:33
@fregataa fregataa requested a review from a team as a code owner May 18, 2026 03:33
@github-actions github-actions Bot added the size:M 30~100 LoC label May 18, 2026
@github-actions github-actions Bot added comp:manager Related to Manager component comp:common Related to Common component labels May 18, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a typed UserID identifier and adds a new auth service action to resolve a keypair owner’s user UUID from an access key, so callers can avoid depending on the keypairs table directly.

Changes:

  • Added UserID = NewType("UserID", UUID) under ai.backend.common.identifier.user.
  • Implemented ResolveUserIDByAccessKeyAction + result type and wired it into AuthService / AuthProcessors.
  • Added repository + DB source methods to fetch the owning user UUID for a given access key and raise AccessKeyNotFound when missing.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/ai/backend/manager/services/auth/service.py Adds resolve_user_id_by_access_key() service method backed by the auth repository.
src/ai/backend/manager/services/auth/processors.py Registers the new action processor and adds it to supported_actions().
src/ai/backend/manager/services/auth/actions/resolve_user_id_by_access_key.py Defines the new action + result dataclasses.
src/ai/backend/manager/repositories/auth/repository.py Adds repository method get_user_id_by_access_key().
src/ai/backend/manager/repositories/auth/db_source/db_source.py Adds DB query to resolve keypairs.user by access_key and raises AccessKeyNotFound.
src/ai/backend/common/identifier/user.py Introduces UserID NewType for typed UUID discrimination.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ai/backend/manager/repositories/auth/db_source/db_source.py Outdated
Comment thread src/ai/backend/manager/repositories/auth/db_source/db_source.py Outdated
Comment thread src/ai/backend/manager/repositories/auth/db_source/db_source.py Outdated
Comment thread src/ai/backend/manager/repositories/auth/db_source/db_source.py Outdated
Tighten the resolve-user-id-by-access-key chain so the repository and
db_source both accept AccessKey instead of plain str (matching the
action field), drop the redundant UUID(str(row)) re-parse on the
GUID-mapped keypairs.user column, and add success / not-found unit
coverage on AuthRepository.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added size:L 100~500 LoC and removed size:M 30~100 LoC labels May 18, 2026
@fregataa fregataa requested a review from a team May 18, 2026 06:25
return row.domain_name, row.role

@auth_db_source_resilience.apply()
async def fetch_user_id_by_access_key(self, access_key: AccessKey) -> UserID:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question, is there a reason this file uses the Core API and a direct connection instead of the ORM and db_session?

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

Labels

comp:common Related to Common component comp:manager Related to Manager component size:L 100~500 LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants