fix: cleanup obsoleted legacy api keys on api startup (cli / connect) (#1630)

- these keys have been replaced with a session based authorization system
This commit is contained in:
Pujit Mehrotra
2025-08-27 16:37:13 -04:00
committed by GitHub
parent ab11e7ff7f
commit 6469d002b7

View File

@@ -35,11 +35,29 @@ export class ApiKeyService implements OnModuleInit {
async onModuleInit() { async onModuleInit() {
this.memoryApiKeys = await this.loadAllFromDisk(); this.memoryApiKeys = await this.loadAllFromDisk();
await this.cleanupLegacyInternalKeys();
if (environment.IS_MAIN_PROCESS) { if (environment.IS_MAIN_PROCESS) {
this.setupWatch(); this.setupWatch();
} }
} }
private async cleanupLegacyInternalKeys() {
const legacyNames = ['CliInternal', 'ConnectInternal'];
const keysToDelete = this.memoryApiKeys.filter((key) => legacyNames.includes(key.name));
if (keysToDelete.length > 0) {
try {
await this.deleteApiKeys(keysToDelete.map((key) => key.id));
this.logger.log(`Cleaned up ${keysToDelete.length} legacy internal keys`);
} catch (error) {
this.logger.debug(
error,
`Failed to delete legacy internal keys: ${keysToDelete.map((key) => key.name).join(', ')}`
);
}
}
}
public async findAll(): Promise<ApiKey[]> { public async findAll(): Promise<ApiKey[]> {
return this.memoryApiKeys; return this.memoryApiKeys;
} }