Skip to content

Commit

Permalink
Merge pull request #320 from YouKnowBlom/rework-cred
Browse files Browse the repository at this point in the history
Refactor credentialManager to use new interface instead of Configuration
  • Loading branch information
dkanada authored Aug 5, 2021
2 parents 0e64c17 + a468cef commit ba13546
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
11 changes: 6 additions & 5 deletions src/__tests__/credentialManager.test.ts
Original file line number Diff line number Diff line change
@@ -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'
};

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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];
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit ba13546

Please sign in to comment.