mirror of
https://github.com/unraid/api.git
synced 2025-12-31 13:39:52 -06:00
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:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user