From d28e762c555f0de86a8ca7d97fa3e210f596baef Mon Sep 17 00:00:00 2001 From: Matt Gibson Date: Wed, 3 Nov 2021 15:11:06 -0400 Subject: [PATCH] Migrate keys to match api.service storage keys --- common/src/services/apiKey.service.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/common/src/services/apiKey.service.ts b/common/src/services/apiKey.service.ts index 0b67781b..49dbb9d6 100644 --- a/common/src/services/apiKey.service.ts +++ b/common/src/services/apiKey.service.ts @@ -5,8 +5,10 @@ import { TokenService } from '../abstractions/token.service'; import { Utils } from '../misc/utils'; const Keys = { - clientId: 'clientId', - clientSecret: 'clientSecret', + clientIdOld: 'clientId', // TODO: remove this migration when we are confident existing api keys are all migrated. Probably 1-2 releases. + clientId: 'apikey_clientId', + clientSecretOld: 'clientSecret', // TODO: remove this migration when we are confident existing api keys are all migrated. Probably 1-2 releases. + clientSecret: 'apikey_clientSecret', entityType: 'entityType', entityId: 'entityId', }; @@ -20,6 +22,22 @@ export class ApiKeyService implements ApiKeyServiceAbstraction { constructor(private tokenService: TokenService, private storageService: StorageService) { } + // TODO: remove this migration when we are confident existing api keys are all migrated. Probably 1-2 releases. + async migrateApiKeyStorage() { + const oldClientId = await this.storageService.get(Keys.clientIdOld); + const oldClientSecret = await this.storageService.get(Keys.clientSecretOld); + + if (oldClientId != null) { + await this.storageService.save(Keys.clientId, oldClientId); + await this.storageService.remove(Keys.clientIdOld); + } + + if (oldClientSecret != null) { + await this.storageService.save(Keys.clientSecret, oldClientSecret); + await this.storageService.remove(Keys.clientSecretOld); + } + } + async setInformation(clientId: string, clientSecret: string) { this.clientId = clientId; this.clientSecret = clientSecret;