Skip to content
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

chore: delete project api tokens when last mapped project is removed #7503

Merged

Conversation

daveleek
Copy link
Contributor

@daveleek daveleek commented Jul 1, 2024

Removes API token when last project it is mapped to is deleted

Copy link

vercel bot commented Jul 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
unleash-monorepo-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 9, 2024 11:32am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) Visit Preview Jul 9, 2024 11:32am

Copy link
Contributor

github-actions bot commented Jul 1, 2024

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Manifest Files

@daveleek
Copy link
Contributor Author

daveleek commented Jul 1, 2024

Currently lacks unit tests

@daveleek daveleek marked this pull request as ready for review July 3, 2024 08:29
@daveleek daveleek changed the title [WIP] chore: delete project api tokens when last mapped project is removed chore: delete project api tokens when last mapped project is removed Jul 3, 2024
@@ -109,6 +111,8 @@ export const createProjectService = (
eventService,
);

const apiTokenStore = new ApiTokenStore(db, eventBus, getLogger);
Copy link
Contributor

Choose a reason for hiding this comment

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

should the project service use the api token store or the service? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm fine either way on this one. If we want to move more in the direction of talking between services and not stores then perhaps this is the way to go

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure. Just to be clear: I don't know (and don't really have a strong opinion one way or the other 🤷🏼 ). Just came to think of it.

@@ -89,6 +91,7 @@ beforeAll(async () => {

environmentService = new EnvironmentService(stores, config, eventService);
projectService = createProjectService(db.rawDatabase, config);
apiTokenService = new ApiTokenService(stores, config, eventService);
Copy link
Contributor

Choose a reason for hiding this comment

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

Making a note for myself to update this after merging this. We're updating the api token service to use the new create(Fake)?ApiTokenService pattern (in merged pr #7519), so I can go and fix this one up too.

src/lib/features/project/project-service.e2e.test.ts Outdated Show resolved Hide resolved
src/lib/features/project/project-service.e2e.test.ts Outdated Show resolved Hide resolved
src/lib/features/project/project-service.e2e.test.ts Outdated Show resolved Hide resolved
Comment on lines 568 to 574
const projectTokens = allTokens.filter(
(token) =>
(token.projects &&
token.projects.length === 1 &&
token.projects[0] === id) ||
token.project === id,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is essentially looking for tokens that only have a single project, and that project has id id, right?

Not important, but is there a nicer way to do it? I think even with 24k tokens it should be fine, but how about something like:

const tokens = await this.apiTokenStore.getTokensForProject(id);
const toDelete = tokens.filter(token => token.project || token.projects.length === 1)

Or something like that? 🤷🏼 Not important, though. Oh, I also don't know if we have a method like that, soooo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn't find this.apiTokenStore.getTokensForProject, I guess we could add this method though

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, it was just an idea I had (and def not a blocker). I think that method might be useful, but if this is the only place we do that, then ... eh 🤷🏼

@thomasheartman thomasheartman merged commit 2e5d81c into main Jul 9, 2024
12 checks passed
@thomasheartman thomasheartman deleted the chore/delete-project-tokens-when-removing-last-project branch July 9, 2024 11:49
thomasheartman added a commit that referenced this pull request Jul 9, 2024
PR #7519 introduced the pattern of using `createApiTokenService` instead
of newing it up. This usage was introduced in a concurrent PR (#7503),
so we're just cleaning up and making the usage consistent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants