Skip to content

feat(repository): LookupAppToken() queries and repository function#6420

Open
dkanney wants to merge 19 commits intollb-app-tokenfrom
dkanney-get-token
Open

feat(repository): LookupAppToken() queries and repository function#6420
dkanney wants to merge 19 commits intollb-app-tokenfrom
dkanney-get-token

Conversation

@dkanney
Copy link
Collaborator

@dkanney dkanney commented Feb 9, 2026

ICU-17931

Description

  • Global, Org, and Project queries to fetch core App Token data alongside its permission data
  • LookupAppToken() repository method utilizes these queries (based on token subtype) to fetch full app token information, including token cipher and permission data

PCI review checklist

  • I have documented a clear reason for, and description of, the change I am making.
  • If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request.
  • If applicable, I've documented the impact of any changes to security controls.
    Examples of changes to security controls include using new access control methods, adding or removing logging pipelines, etc.

@dkanney dkanney force-pushed the dkanney-get-token branch 3 times, most recently from 168a749 to 00e078d Compare February 11, 2026 05:08
@dkanney dkanney marked this pull request as ready for review February 11, 2026 05:33
@dkanney dkanney requested a review from a team as a code owner February 11, 2026 05:33
Copy link

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

Adds repository support for looking up full App Token details (token cipher + permissions) and updates token/grant retrieval logic and tests accordingly.

Changes:

  • Introduces LookupAppToken() plus supporting DB queries to fetch core token fields and permissions in one call (by token subtype).
  • Updates CreateAppToken() to re-read tokens via LookupAppToken() within the same transaction.
  • Expands tests and replaces string literals for grant scopes with constants.

Reviewed changes

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

Show a summary per file
File Description
internal/iam/role.go Removes redundant return in a no-op method.
internal/apptoken/repository_token_grant.go Uses token scope lookup to drive grant queries.
internal/apptoken/repository_test.go Adds LookupAppToken tests and normalizes grant scope constants.
internal/apptoken/repository.go Implements LookupAppToken, refactors token creation to use it, adds scope helpers.
internal/apptoken/query.go Adds new SQL queries for global/org/project token lookup and scope-id lookup.
internal/apptoken/options.go Adds option to reuse an in-flight transaction (reader/writer).

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

@dkanney dkanney requested a review from Copilot February 12, 2026 19:25
Copy link

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

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


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

}

// getAppTokenScopeId returns the scope id of the app token
func getAppTokenScopeId(ctx context.Context, reader db.Reader, id string) (string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this be a method so that reader isn't being passed in? If not, can you add to the comment why it's necessary that it's not a method

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we need the ability to pass around a reader when calling this function inside a transaction

e.g. CreateAppToken() -> open a new Tx with its own dedicated reader -> call LookupAppToken() w/ the the Tx reader -> call getAppTokenScopeId() with the Tx reader

…istancy with input

Project-scoped tokens can only apply to themselves, so the only active scope will be the project itself. No need to assign the project to its own "active_grant_scope_ids" array because we just need to check if "grant_this_scope" is true. This also matches the shape of input project tokens; those only need to specify "grant_this_scope".

Also remove some extraneous grouping.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants