From 05ff1023fa6e57710a1f433398c96ec96df28bb0 Mon Sep 17 00:00:00 2001 From: Andreas B <6439218+YouKnowBlom@users.noreply.github.com> Date: Thu, 22 Jul 2021 16:30:38 +0000 Subject: [PATCH 1/2] Move credentialManager outside of api folder --- src/{api => components}/credentialManager.ts | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{api => components}/credentialManager.ts (100%) diff --git a/src/api/credentialManager.ts b/src/components/credentialManager.ts similarity index 100% rename from src/api/credentialManager.ts rename to src/components/credentialManager.ts From a468cef64c69f712095780f278fb5228449c807d Mon Sep 17 00:00:00 2001 From: Andreas B <6439218+YouKnowBlom@users.noreply.github.com> Date: Thu, 22 Jul 2021 16:44:05 +0000 Subject: [PATCH 2/2] Use ServerCredential interface in credentialManager --- src/__tests__/credentialManager.test.ts | 11 ++++++----- src/components/credentialManager.ts | 22 +++++++++++++--------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/__tests__/credentialManager.test.ts b/src/__tests__/credentialManager.test.ts index 959ebd28..fbe6feef 100644 --- a/src/__tests__/credentialManager.test.ts +++ b/src/__tests__/credentialManager.test.ts @@ -1,14 +1,15 @@ -import { Configuration } from '../api/generated/configuration'; - -import { credentialManager } from '../api/credentialManager'; +import { + credentialManager, + ServerCredential +} from '../components/credentialManager'; const serverId1 = 'f4486b851af24255b3305fe614b81f01'; -const serverConfig1: Configuration = { +const serverConfig1: ServerCredential = { apiKey: 'b49268e51af24255b3305fe614b81f01' }; const serverId2 = 'af72hb851af24255b3305fe614b81f01'; -const serverConfig2: Configuration = { +const serverConfig2: ServerCredential = { apiKey: 'd4286b8119f24a55b3305fe614b81f01' }; diff --git a/src/components/credentialManager.ts b/src/components/credentialManager.ts index abb66174..90dce8ac 100644 --- a/src/components/credentialManager.ts +++ b/src/components/credentialManager.ts @@ -1,7 +1,11 @@ -import { Configuration } from './generated/configuration'; +export interface ServerCredential { + apiKey?: string; + accessToken?: string; + serverBasePath?: string; +} interface CredentialStore { - [id: string]: Configuration; + [id: string]: ServerCredential; } export class credentialManager { @@ -28,7 +32,7 @@ export class credentialManager { * @returns Credentials for the provided server ID. * or undefined if the store has no server with that ID. */ - get(serverId: string): Configuration | undefined { + get(serverId: string): ServerCredential | undefined { if (serverId in this.credentialStore) { return this.credentialStore[serverId]; } @@ -38,12 +42,12 @@ export class credentialManager { * Update credentials for the provided server ID. * * @param serverId - ID of the server to update. - * @param newConfig - Updated Credentials. + * @param newCredentials - Updated Credentials. * @returns True if the value was updated, false if it wasn't. */ - update(serverId: string, newConfig: Configuration): boolean { + update(serverId: string, newCredentials: ServerCredential): boolean { if (serverId in this.credentialStore) { - this.credentialStore[serverId] = newConfig; + this.credentialStore[serverId] = newCredentials; return true; } @@ -55,15 +59,15 @@ export class credentialManager { * Add a new credential to store. Only accepts new entries. * * @param serverId - ID of the server the credentials belong to. - * @param configuration - Credentials of the server. + * @param credentials - Credentials of the server. * @returns True if server was added, false if it wasn't. */ - add(serverId: string, configuration: Configuration): boolean { + add(serverId: string, credentials: ServerCredential): boolean { if (serverId in this.credentialStore) { return false; } - this.credentialStore[serverId] = configuration; + this.credentialStore[serverId] = credentials; return true; }