Skip to content

feat: add name and token_last_characters to apitoken #58945

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 7 commits into from
Oct 31, 2023

Conversation

mdtro
Copy link
Member

@mdtro mdtro commented Oct 27, 2023

  • Add a nullable name column to the ApiToken model to help users identify and give meaningful names to their API tokens.
  • Add a nullable last_token_characters column that will contain the last four characters of the API token to help users with identify the token in the UI when the majority of it is obfuscated.

Supports #58918

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 27, 2023
@mdtro mdtro force-pushed the mdtro/improved-apitoken-1 branch from 49b0d5b to 4df66e6 Compare October 27, 2023 17:57
@github-actions
Copy link
Contributor

This PR has a migration; here is the generated SQL for src/sentry/migrations/0584_apitoken_add_name_and_last_chars.py ()

--
-- Add field name to apitoken
--
ALTER TABLE "sentry_apitoken" ADD COLUMN "name" varchar(255) NULL;
--
-- Add field token_last_characters to apitoken
--
ALTER TABLE "sentry_apitoken" ADD COLUMN "token_last_characters" varchar(4) NULL;

@mdtro mdtro marked this pull request as ready for review October 27, 2023 18:00
@mdtro mdtro requested a review from a team as a code owner October 27, 2023 18:00
@mdtro mdtro linked an issue Oct 27, 2023 that may be closed by this pull request
@mdtro mdtro marked this pull request as draft October 27, 2023 18:14
Copy link
Contributor

@azaslavsky azaslavsky left a comment

Choose a reason for hiding this comment

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

Do you mind updating the code in tests/sentry/backup/test_models.py and src/sentry/testutils/helpers/backups.py (<- 2 usages) to use these fields as well?

Also, more generally, may be worthwhile adding a couple of general-case tests in ex: test_authetnication.py, test_sentryapp.py, etc.

@codecov
Copy link

codecov bot commented Oct 27, 2023

Codecov Report

Merging #58945 (b7e3250) into master (883c8b9) will increase coverage by 0.01%.
Report is 3 commits behind head on master.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master   #58945      +/-   ##
==========================================
+ Coverage   80.64%   80.65%   +0.01%     
==========================================
  Files        5157     5157              
  Lines      226028   226030       +2     
  Branches    38078    38078              
==========================================
+ Hits       182273   182312      +39     
+ Misses      38187    38149      -38     
- Partials     5568     5569       +1     
Files Coverage Δ
src/sentry/backup/comparators.py 94.35% <ø> (ø)
src/sentry/models/apitoken.py 98.96% <100.00%> (+0.02%) ⬆️
src/sentry/testutils/helpers/backups.py 98.46% <100.00%> (ø)

... and 9 files with indirect coverage changes

@mdtro mdtro force-pushed the mdtro/improved-apitoken-1 branch from f17208b to b7e3250 Compare October 31, 2023 20:01
@mdtro mdtro marked this pull request as ready for review October 31, 2023 20:35
@mdtro mdtro requested a review from a team October 31, 2023 20:35
@mdtro mdtro merged commit e3cf39f into master Oct 31, 2023
@mdtro mdtro deleted the mdtro/improved-apitoken-1 branch October 31, 2023 21:58
@github-actions github-actions bot locked and limited conversation to collaborators Nov 16, 2023
@mdtro mdtro linked an issue Feb 2, 2024 that may be closed by this pull request
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: add name and token_last_characters to ApiToken
3 participants