-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up SCM connections of installation admin (#19601)
- Loading branch information
1 parent
949af13
commit d38b01c
Showing
4 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Copyright (c) 2024 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { BUILTIN_INSTLLATION_ADMIN_USER_ID, UserDB } from "@gitpod/gitpod-db/lib"; | ||
import { log } from "@gitpod/gitpod-protocol/lib/util/logging"; | ||
import { inject, injectable } from "inversify"; | ||
import { Job } from "./runner"; | ||
|
||
@injectable() | ||
export class InstallationAdminCleanup implements Job { | ||
@inject(UserDB) protected readonly userDb: UserDB; | ||
|
||
public name = "installation-admin-cleanup"; | ||
public frequencyMs = 5 * 60 * 1000; // every 5 minutes | ||
|
||
public async run(): Promise<void> { | ||
try { | ||
const installationAdmin = await this.userDb.findUserById(BUILTIN_INSTLLATION_ADMIN_USER_ID); | ||
if (!installationAdmin) { | ||
return; | ||
} | ||
|
||
let cleanupRequired = false; | ||
for (const identity of installationAdmin.identities) { | ||
cleanupRequired = true; | ||
identity.deleted = true; | ||
await this.userDb.deleteTokens(identity); | ||
} | ||
if (cleanupRequired) { | ||
await this.userDb.storeUser(installationAdmin); | ||
log.info("Cleaned up SCM connections of installation admin."); | ||
} | ||
} catch (err) { | ||
log.error("Failed to clean up SCM connections of installation admin.", err); | ||
throw err; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters