Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor credentialManager to use new interface instead of Configuration #320

Merged
merged 2 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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