Skip to content

[public-api] Implement delete token #14877

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

Merged
merged 1 commit into from
Nov 23, 2022
Merged

[public-api] Implement delete token #14877

merged 1 commit into from
Nov 23, 2022

Conversation

jeanp413
Copy link
Member

Description

Implements delete token

Related Issue(s)

Fixes #14613

Release Notes

NONE

Documentation

Werft options:

  • /werft with-local-preview
    If enabled this will build install/preview
  • /werft with-preview
  • /werft with-large-vm
  • /werft with-integration-tests=all
    Valid options are all, workspace, webapp, ide, jetbrains, vscode, ssh

@jeanp413 jeanp413 requested a review from a team November 23, 2022 07:59
@github-actions github-actions bot added the team: webapp Issue belongs to the WebApp team label Nov 23, 2022
@jeanp413
Copy link
Member Author

jeanp413 commented Nov 23, 2022

/werft run

👍 started the job as gitpod-build-jp-public-api-delete.1
(with .werft/ from main)

@jeanp413 jeanp413 force-pushed the jp/public-api-delete branch from d055e2f to 4d60dbb Compare November 23, 2022 08:02
Where("deleted = ?", 0).
Update("deleted", 1)
if db.Error != nil {
return 0, fmt.Errorf("Failed to delete token: %v", db.Error)
Copy link
Member

Choose a reason for hiding this comment

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

[nit] To follow Go recommended style.

Suggested change
return 0, fmt.Errorf("Failed to delete token: %v", db.Error)
return 0, fmt.Errorf("failed to delete token (ID: %s): %v", tokenID.String(), db.Error)

We do use first letter uppercase in the API Handlers to provide a cleaner user-facing error message, but here in the db package we can stick to standard Go practice.

Here, the suggestion also includes the Token ID in the error. This makes tracking down the entry a bit simpler and I'd generally recommend including non sensitive IDs in the errors like this

There are a couple more occurrences of the uppercase.

Copy link
Contributor

Choose a reason for hiding this comment

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

We have lots of params checkings like code below, they are uppercase too, should we change them all? If so, it could be a follow-up PR. cc @easyCZ

if req.UserID == uuid.Nil {
	return PersonalAccessToken{}, fmt.Errorf("Invalid or empty userID")
}

Copy link
Member

Choose a reason for hiding this comment

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

So the only place where we "should" use Uppercase is the apiv1 handler code. As that's what ultimately returns a response to the user. Everywhere else errors should start with lowercase as per standard go style. Sorry, this is a bit confusing. Maybe I can write a middleware which uppercases the first letter of the error to get rid of this inconcistency.

Co-authored-by: Milan Pavlik <[email protected]>
Co-authored-by: mustard <[email protected]>
Copy link
Member

@easyCZ easyCZ left a comment

Choose a reason for hiding this comment

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

Nice work!

@roboquat roboquat merged commit d700721 into main Nov 23, 2022
@roboquat roboquat deleted the jp/public-api-delete branch November 23, 2022 15:11
@roboquat roboquat added deployed: webapp Meta team change is running in production deployed Change is completely running in production labels Nov 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployed: webapp Meta team change is running in production deployed Change is completely running in production release-note-none size/L team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement DeletePersonalAccessToken RPC
4 participants