Skip to content

Conversation

@mikemountain
Copy link
Collaborator

@mikemountain mikemountain commented Jan 14, 2026

Description

This PR adds the functionality to delete an apptoken.

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.

@mikemountain mikemountain force-pushed the mikemountain-apptoken-repo-delete branch from 49d1825 to 1eb7f9e Compare January 29, 2026 19:39
Copy link
Collaborator

@AprilMay0 AprilMay0 left a comment

Choose a reason for hiding this comment

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

I'm wondering if we should delete directly from the app_token table rather than the subtype tables. The app_token table cascades down to the subtype tables, so deleting from app_token will automatically cascade to app_token_org/app_token_global/app_token_project and trigger the insert_deleted_id trigger to record the deletion in app_token_deleted.

Comment on lines 591 to 611
scopeType, err := getAppTokenScopeType(ctx, r.reader, publicId)
if err != nil {
return db.NoRowsAffected, errors.Wrap(ctx, err, op, errors.WithMsg("cannot get scope for app token %s", publicId))
}

var tokenToDelete any
switch scopeType {
case scope.Global:
gToken := allocGlobalAppToken()
gToken.PublicId = publicId
tokenToDelete = &gToken
case scope.Org:
oToken := allocOrgAppToken()
oToken.PublicId = publicId
tokenToDelete = &oToken
case scope.Project:
pToken := allocProjectAppToken()
pToken.PublicId = publicId
tokenToDelete = &pToken
default:
return db.NoRowsAffected, errors.New(ctx, errors.Unknown, op, fmt.Sprintf("unknown scope type for app token: %s", publicId))
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should be able to just delete from app_token table and rely on on delete cascade trigger to delete the rest

assert.True(errors.IsNotFoundError(err))
})

t.Run("invalid-id", func(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add a test that deletes a non-existent token.

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