-
Notifications
You must be signed in to change notification settings - Fork 310
feat(repository): Implement Delete app token functionality #6341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: llb-app-token
Are you sure you want to change the base?
Conversation
49d1825 to
1eb7f9e
Compare
AprilMay0
left a comment
There was a problem hiding this 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.
internal/apptoken/repository.go
Outdated
| 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)) |
There was a problem hiding this comment.
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
internal/apptoken/repository_test.go
Outdated
| assert.True(errors.IsNotFoundError(err)) | ||
| }) | ||
|
|
||
| t.Run("invalid-id", func(t *testing.T) { |
There was a problem hiding this comment.
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.
Description
This PR adds the functionality to delete an apptoken.
PCI review checklist
Examples of changes to security controls include using new access control methods, adding or removing logging pipelines, etc.