Skip to content

Commit

Permalink
feat(keychain-azure-kv): complete request handler and endpoints
Browse files Browse the repository at this point in the history
Fixes hyperledger-cacti#1010

Signed-off-by: Youngone Lee <youngone.lee@accenture.com>
  • Loading branch information
Leeyoungone committed Aug 20, 2021
1 parent 951b9f1 commit 15dc7e6
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 292 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@ import {
PluginFactory,
PluginImportType,
} from "@hyperledger/cactus-core-api";
import {
Configuration,
DefaultApi,
} from "./generated/openapi/typescript-axios";
import {
IPluginKeychainAzureKvOptions,
PluginKeychainAzureKv,
} from "./plugin-keychain-azure-kv";

import { PluginKeychainAzureKvRemoteAdapter } from "./plugin-keychain-azure-kv-remote-adapter";

export class PluginFactoryKeychain extends PluginFactory<
IPluginKeychain,
IPluginKeychainAzureKvOptions,
Expand All @@ -26,23 +20,10 @@ export class PluginFactoryKeychain extends PluginFactory<

const { pluginImportType } = this.options;
Checks.truthy(options, `${fnTag}:options`);

switch (pluginImportType) {
case PluginImportType.Local: {
return new PluginKeychainAzureKv(options);
}
case PluginImportType.Remote: {
const { remoteConfig } = options;
Checks.truthy(remoteConfig, `${fnTag}:options.remoteConfig`);
Checks.truthy(remoteConfig.basePath, `${fnTag}:remoteConfig.basePath`);
const configuration: Configuration = options.remoteConfig;
const backend = new DefaultApi(configuration);
const optionsDecorated = { ...options, backend };
return new PluginKeychainAzureKvRemoteAdapter(optionsDecorated);
}
default: {
throw new Error(`${fnTag} No PluginImportType: ${pluginImportType}`);
}
if (pluginImportType === PluginImportType.Local) {
return new PluginKeychainAzureKv(options);
} else {
throw new Error(`${fnTag} No PluginImportType: ${pluginImportType}`);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { PluginRegistry } from "@hyperledger/cactus-core";
import {
IPluginFactoryOptions,
PluginImportType,
} from "@hyperledger/cactus-core-api";
import test, { Test } from "tape-promise/tape";
import { PluginFactoryKeychain } from "../../../main/typescript/plugin-factory-keychain";
import {
AzureCredentialType,
PluginKeychainAzureKv,
} from "../../../main/typescript/plugin-keychain-azure-kv";
import { v4 as uuidv4 } from "uuid";

test("get,set,has,delete alters state as expected", async (t: Test) => {
const iPluginFactoryOptions1: IPluginFactoryOptions = {
pluginImportType: PluginImportType.Local,
};

const invalid: IPluginFactoryOptions = {
pluginImportType: (null as unknown) as PluginImportType,
};

const pluginRegistry = new PluginRegistry();
const iPluginKeychainAzureKvOptions = {
instanceId: uuidv4(),
keychainId: uuidv4(),
pluginRegistry,
azureEndpoint: "true",
azureRegion: "us-east-1",
azureProfile: "default",
azureCredentialType: AzureCredentialType.InMemory,
azureAccessKeyId: "fake",
azureSecretAccessKey: "fake",
logLevel: "TRACE",
};

const pluginFactoryKeychain1 = new PluginFactoryKeychain(
iPluginFactoryOptions1,
);

const pluginFactoryKeychain3 = new PluginFactoryKeychain(invalid);

const pluginKeychainAzureKv = await pluginFactoryKeychain1.create(
iPluginKeychainAzureKvOptions,
);

t.true(
pluginKeychainAzureKv instanceof PluginKeychainAzureKv,
"pluginImportType.Local results in pluginKeychainAzureKv",
);

await t.rejects(
pluginFactoryKeychain3.create({
invalid,
}),
);

t.end();
});

This file was deleted.

This file was deleted.

0 comments on commit 15dc7e6

Please sign in to comment.