diff --git a/packages/cactus-plugin-keychain-aws-sm/src/main/json/openapi.json b/packages/cactus-plugin-keychain-aws-sm/src/main/json/openapi.json index 67d9aa3c1d..c40f6ee993 100644 --- a/packages/cactus-plugin-keychain-aws-sm/src/main/json/openapi.json +++ b/packages/cactus-plugin-keychain-aws-sm/src/main/json/openapi.json @@ -31,7 +31,7 @@ "verbLowerCase": "post" } }, - "operationId": "getKeychainEntry", + "operationId": "getKeychainEntryV1", "summary": "Retrieves the contents of a keychain entry from the backend.", "parameters": [], "requestBody": { @@ -64,7 +64,7 @@ "verbLowerCase": "post" } }, - "operationId": "setKeychainEntry", + "operationId": "setKeychainEntryV1", "summary": "Sets a value under a key on the keychain backend.", "parameters": [], "requestBody": { @@ -85,6 +85,66 @@ } } } + }, + "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-aws-sm/delete-keychain-entry": { + "post": { + "x-hyperledger-cactus": { + "http": { + "path": "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-aws-sm/delete-keychain-entry", + "verbLowerCase": "post" + } + }, + "operationId": "deleteKeychainEntryV1", + "summary": "Deletes an entry under a key on the keychain backend.", + "parameters": [], + "requestBody": { + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.9.0/packages/cactus-core-api/src/main/json/openapi.json#/components/requestBodies/keychain_delete_entry_request_body" + }, + "responses": { + "200": { + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.9.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_delete_entry_200" + }, + "400": { + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.9.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_delete_entry_400" + }, + "401": { + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.9.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_delete_entry_401" + }, + "500": { + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.9.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_delete_entry_500" + } + } + } + }, + "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-aws-sm/has-keychain-entry": { + "post": { + "x-hyperledger-cactus": { + "http": { + "path": "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-aws-sm/has-keychain-entry", + "verbLowerCase": "post" + } + }, + "operationId": "hasKeychainEntryV1", + "summary": "Checks that an entry exists under a key on the keychain backend", + "parameters": [], + "requestBody": { + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.9.0/packages/cactus-core-api/src/main/json/openapi.json#/components/requestBodies/keychain_has_entry_request_body" + }, + "responses": { + "200": { + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.9.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_has_entry_200" + }, + "400": { + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.9.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_has_entry_400" + }, + "401": { + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.9.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_has_entry_401" + }, + "500": { + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.9.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_has_entry_500" + } + } + } } } -} \ No newline at end of file +} diff --git a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/generated/openapi/typescript-axios/api.ts b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/generated/openapi/typescript-axios/api.ts index 6c76cab18d..5aa7e36797 100644 --- a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/generated/openapi/typescript-axios/api.ts +++ b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/generated/openapi/typescript-axios/api.ts @@ -21,6 +21,32 @@ import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObj // @ts-ignore import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from './base'; +/** + * + * @export + * @interface DeleteKeychainEntryRequestV1 + */ +export interface DeleteKeychainEntryRequestV1 { + /** + * The key for the entry to check the presence of on the keychain. + * @type {string} + * @memberof DeleteKeychainEntryRequestV1 + */ + key: string; +} +/** + * + * @export + * @interface DeleteKeychainEntryResponseV1 + */ +export interface DeleteKeychainEntryResponseV1 { + /** + * The key that was deleted from the keychain. + * @type {string} + * @memberof DeleteKeychainEntryResponseV1 + */ + key: string; +} /** * * @export @@ -53,6 +79,44 @@ export interface GetKeychainEntryResponse { */ value: string; } +/** + * + * @export + * @interface HasKeychainEntryRequestV1 + */ +export interface HasKeychainEntryRequestV1 { + /** + * The key to check for presence in the keychain. + * @type {string} + * @memberof HasKeychainEntryRequestV1 + */ + key: string; +} +/** + * + * @export + * @interface HasKeychainEntryResponseV1 + */ +export interface HasKeychainEntryResponseV1 { + /** + * The key that was used to check the presence of the value in the entry store. + * @type {string} + * @memberof HasKeychainEntryResponseV1 + */ + key: string; + /** + * Date and time encoded as JSON when the presence check was performed by the plugin backend. + * @type {string} + * @memberof HasKeychainEntryResponseV1 + */ + checkedAt: string; + /** + * The boolean true or false indicating the presence or absence of an entry under \'key\'. + * @type {boolean} + * @memberof HasKeychainEntryResponseV1 + */ + isPresent: boolean; +} /** * * @export @@ -92,6 +156,42 @@ export interface SetKeychainEntryResponse { */ export const DefaultApiAxiosParamCreator = function (configuration?: Configuration) { return { + /** + * + * @summary Deletes an entry under a key on the keychain backend. + * @param {DeleteKeychainEntryRequestV1} deleteKeychainEntryRequestV1 Request body to delete a keychain entry via its key + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + deleteKeychainEntryV1: async (deleteKeychainEntryRequestV1: DeleteKeychainEntryRequestV1, options: any = {}): Promise => { + // verify required parameter 'deleteKeychainEntryRequestV1' is not null or undefined + assertParamExists('deleteKeychainEntryV1', 'deleteKeychainEntryRequestV1', deleteKeychainEntryRequestV1) + const localVarPath = `/api/v1/plugins/@hyperledger/cactus-plugin-keychain-aws-sm/delete-keychain-entry`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + + + localVarHeaderParameter['Content-Type'] = 'application/json'; + + setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + localVarRequestOptions.data = serializeDataIfNeeded(deleteKeychainEntryRequestV1, localVarRequestOptions, configuration) + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, /** * * @summary Retrieves the contents of a keychain entry from the backend. @@ -99,9 +199,9 @@ export const DefaultApiAxiosParamCreator = function (configuration?: Configurati * @param {*} [options] Override http request option. * @throws {RequiredError} */ - getKeychainEntry: async (getKeychainEntryRequest: GetKeychainEntryRequest, options: any = {}): Promise => { + getKeychainEntryV1: async (getKeychainEntryRequest: GetKeychainEntryRequest, options: any = {}): Promise => { // verify required parameter 'getKeychainEntryRequest' is not null or undefined - assertParamExists('getKeychainEntry', 'getKeychainEntryRequest', getKeychainEntryRequest) + assertParamExists('getKeychainEntryV1', 'getKeychainEntryRequest', getKeychainEntryRequest) const localVarPath = `/api/v1/plugins/@hyperledger/cactus-plugin-keychain-aws-sm/get-keychain-entry`; // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); @@ -128,6 +228,42 @@ export const DefaultApiAxiosParamCreator = function (configuration?: Configurati options: localVarRequestOptions, }; }, + /** + * + * @summary Checks that an entry exists under a key on the keychain backend + * @param {HasKeychainEntryRequestV1} hasKeychainEntryRequestV1 Request body for checking a keychain entry via its key + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + hasKeychainEntryV1: async (hasKeychainEntryRequestV1: HasKeychainEntryRequestV1, options: any = {}): Promise => { + // verify required parameter 'hasKeychainEntryRequestV1' is not null or undefined + assertParamExists('hasKeychainEntryV1', 'hasKeychainEntryRequestV1', hasKeychainEntryRequestV1) + const localVarPath = `/api/v1/plugins/@hyperledger/cactus-plugin-keychain-aws-sm/has-keychain-entry`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + + + localVarHeaderParameter['Content-Type'] = 'application/json'; + + setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + localVarRequestOptions.data = serializeDataIfNeeded(hasKeychainEntryRequestV1, localVarRequestOptions, configuration) + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, /** * * @summary Sets a value under a key on the keychain backend. @@ -135,9 +271,9 @@ export const DefaultApiAxiosParamCreator = function (configuration?: Configurati * @param {*} [options] Override http request option. * @throws {RequiredError} */ - setKeychainEntry: async (setKeychainEntryRequest: SetKeychainEntryRequest, options: any = {}): Promise => { + setKeychainEntryV1: async (setKeychainEntryRequest: SetKeychainEntryRequest, options: any = {}): Promise => { // verify required parameter 'setKeychainEntryRequest' is not null or undefined - assertParamExists('setKeychainEntry', 'setKeychainEntryRequest', setKeychainEntryRequest) + assertParamExists('setKeychainEntryV1', 'setKeychainEntryRequest', setKeychainEntryRequest) const localVarPath = `/api/v1/plugins/@hyperledger/cactus-plugin-keychain-aws-sm/set-keychain-entry`; // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); @@ -174,6 +310,17 @@ export const DefaultApiAxiosParamCreator = function (configuration?: Configurati export const DefaultApiFp = function(configuration?: Configuration) { const localVarAxiosParamCreator = DefaultApiAxiosParamCreator(configuration) return { + /** + * + * @summary Deletes an entry under a key on the keychain backend. + * @param {DeleteKeychainEntryRequestV1} deleteKeychainEntryRequestV1 Request body to delete a keychain entry via its key + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async deleteKeychainEntryV1(deleteKeychainEntryRequestV1: DeleteKeychainEntryRequestV1, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.deleteKeychainEntryV1(deleteKeychainEntryRequestV1, options); + return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); + }, /** * * @summary Retrieves the contents of a keychain entry from the backend. @@ -181,8 +328,19 @@ export const DefaultApiFp = function(configuration?: Configuration) { * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async getKeychainEntry(getKeychainEntryRequest: GetKeychainEntryRequest, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.getKeychainEntry(getKeychainEntryRequest, options); + async getKeychainEntryV1(getKeychainEntryRequest: GetKeychainEntryRequest, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.getKeychainEntryV1(getKeychainEntryRequest, options); + return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); + }, + /** + * + * @summary Checks that an entry exists under a key on the keychain backend + * @param {HasKeychainEntryRequestV1} hasKeychainEntryRequestV1 Request body for checking a keychain entry via its key + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async hasKeychainEntryV1(hasKeychainEntryRequestV1: HasKeychainEntryRequestV1, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.hasKeychainEntryV1(hasKeychainEntryRequestV1, options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, /** @@ -192,8 +350,8 @@ export const DefaultApiFp = function(configuration?: Configuration) { * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async setKeychainEntry(setKeychainEntryRequest: SetKeychainEntryRequest, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.setKeychainEntry(setKeychainEntryRequest, options); + async setKeychainEntryV1(setKeychainEntryRequest: SetKeychainEntryRequest, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.setKeychainEntryV1(setKeychainEntryRequest, options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, } @@ -206,6 +364,16 @@ export const DefaultApiFp = function(configuration?: Configuration) { export const DefaultApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) { const localVarFp = DefaultApiFp(configuration) return { + /** + * + * @summary Deletes an entry under a key on the keychain backend. + * @param {DeleteKeychainEntryRequestV1} deleteKeychainEntryRequestV1 Request body to delete a keychain entry via its key + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + deleteKeychainEntryV1(deleteKeychainEntryRequestV1: DeleteKeychainEntryRequestV1, options?: any): AxiosPromise { + return localVarFp.deleteKeychainEntryV1(deleteKeychainEntryRequestV1, options).then((request) => request(axios, basePath)); + }, /** * * @summary Retrieves the contents of a keychain entry from the backend. @@ -213,8 +381,18 @@ export const DefaultApiFactory = function (configuration?: Configuration, basePa * @param {*} [options] Override http request option. * @throws {RequiredError} */ - getKeychainEntry(getKeychainEntryRequest: GetKeychainEntryRequest, options?: any): AxiosPromise { - return localVarFp.getKeychainEntry(getKeychainEntryRequest, options).then((request) => request(axios, basePath)); + getKeychainEntryV1(getKeychainEntryRequest: GetKeychainEntryRequest, options?: any): AxiosPromise { + return localVarFp.getKeychainEntryV1(getKeychainEntryRequest, options).then((request) => request(axios, basePath)); + }, + /** + * + * @summary Checks that an entry exists under a key on the keychain backend + * @param {HasKeychainEntryRequestV1} hasKeychainEntryRequestV1 Request body for checking a keychain entry via its key + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + hasKeychainEntryV1(hasKeychainEntryRequestV1: HasKeychainEntryRequestV1, options?: any): AxiosPromise { + return localVarFp.hasKeychainEntryV1(hasKeychainEntryRequestV1, options).then((request) => request(axios, basePath)); }, /** * @@ -223,8 +401,8 @@ export const DefaultApiFactory = function (configuration?: Configuration, basePa * @param {*} [options] Override http request option. * @throws {RequiredError} */ - setKeychainEntry(setKeychainEntryRequest: SetKeychainEntryRequest, options?: any): AxiosPromise { - return localVarFp.setKeychainEntry(setKeychainEntryRequest, options).then((request) => request(axios, basePath)); + setKeychainEntryV1(setKeychainEntryRequest: SetKeychainEntryRequest, options?: any): AxiosPromise { + return localVarFp.setKeychainEntryV1(setKeychainEntryRequest, options).then((request) => request(axios, basePath)); }, }; }; @@ -236,6 +414,18 @@ export const DefaultApiFactory = function (configuration?: Configuration, basePa * @extends {BaseAPI} */ export class DefaultApi extends BaseAPI { + /** + * + * @summary Deletes an entry under a key on the keychain backend. + * @param {DeleteKeychainEntryRequestV1} deleteKeychainEntryRequestV1 Request body to delete a keychain entry via its key + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof DefaultApi + */ + public deleteKeychainEntryV1(deleteKeychainEntryRequestV1: DeleteKeychainEntryRequestV1, options?: any) { + return DefaultApiFp(this.configuration).deleteKeychainEntryV1(deleteKeychainEntryRequestV1, options).then((request) => request(this.axios, this.basePath)); + } + /** * * @summary Retrieves the contents of a keychain entry from the backend. @@ -244,8 +434,20 @@ export class DefaultApi extends BaseAPI { * @throws {RequiredError} * @memberof DefaultApi */ - public getKeychainEntry(getKeychainEntryRequest: GetKeychainEntryRequest, options?: any) { - return DefaultApiFp(this.configuration).getKeychainEntry(getKeychainEntryRequest, options).then((request) => request(this.axios, this.basePath)); + public getKeychainEntryV1(getKeychainEntryRequest: GetKeychainEntryRequest, options?: any) { + return DefaultApiFp(this.configuration).getKeychainEntryV1(getKeychainEntryRequest, options).then((request) => request(this.axios, this.basePath)); + } + + /** + * + * @summary Checks that an entry exists under a key on the keychain backend + * @param {HasKeychainEntryRequestV1} hasKeychainEntryRequestV1 Request body for checking a keychain entry via its key + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof DefaultApi + */ + public hasKeychainEntryV1(hasKeychainEntryRequestV1: HasKeychainEntryRequestV1, options?: any) { + return DefaultApiFp(this.configuration).hasKeychainEntryV1(hasKeychainEntryRequestV1, options).then((request) => request(this.axios, this.basePath)); } /** @@ -256,8 +458,8 @@ export class DefaultApi extends BaseAPI { * @throws {RequiredError} * @memberof DefaultApi */ - public setKeychainEntry(setKeychainEntryRequest: SetKeychainEntryRequest, options?: any) { - return DefaultApiFp(this.configuration).setKeychainEntry(setKeychainEntryRequest, options).then((request) => request(this.axios, this.basePath)); + public setKeychainEntryV1(setKeychainEntryRequest: SetKeychainEntryRequest, options?: any) { + return DefaultApiFp(this.configuration).setKeychainEntryV1(setKeychainEntryRequest, options).then((request) => request(this.axios, this.basePath)); } } diff --git a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/plugin-factory-keychain.ts b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/plugin-factory-keychain.ts index dae3179d04..dcb2493919 100644 --- a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/plugin-factory-keychain.ts +++ b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/plugin-factory-keychain.ts @@ -1,31 +1,31 @@ -import { v4 as uuidv4 } from "uuid"; +import { Checks } from "@hyperledger/cactus-common"; import { IPluginFactoryOptions, + IPluginKeychain, PluginFactory, + PluginImportType, } from "@hyperledger/cactus-core-api"; import { - AwsCredentialType, IPluginKeychainAwsSmOptions, PluginKeychainAwsSm, } from "./plugin-keychain-aws-sm"; export class PluginFactoryKeychain extends PluginFactory< - PluginKeychainAwsSm, + IPluginKeychain, IPluginKeychainAwsSmOptions, IPluginFactoryOptions > { - async create( - pluginOptions: IPluginKeychainAwsSmOptions = { - instanceId: uuidv4(), - keychainId: uuidv4(), - logLevel: "TRACE", - awsProfile: "", - awsRegion: "", - awsEndpoint: "", - awsCredentialType: AwsCredentialType.InMemory, - }, - ): Promise { - return new PluginKeychainAwsSm(pluginOptions); + async create(options: any): Promise { + const fnTag = "PluginFactoryKeychain#create()"; + + const { pluginImportType } = this.options; + Checks.truthy(options, `${fnTag}:options`); + + if (pluginImportType === PluginImportType.Local) { + return new PluginKeychainAwsSm(options); + } else { + throw new Error(`${fnTag} No PluginImportType: ${pluginImportType}`); + } } } diff --git a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/plugin-keychain-aws-sm.ts b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/plugin-keychain-aws-sm.ts index 0d1dd00599..5dcd30dd04 100644 --- a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/plugin-keychain-aws-sm.ts +++ b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/plugin-keychain-aws-sm.ts @@ -24,6 +24,11 @@ import { } from "@hyperledger/cactus-core-api"; import { homedir } from "os"; +import { PluginRegistry } from "@hyperledger/cactus-core"; +import { SetKeychainEntryV1Endpoint } from "./webservices/set-keychain-entry-endpoint-v1"; +import { GetKeychainEntryV1Endpoint } from "./webservices/get-keychain-entry-endpoint-v1"; +import { DeleteKeychainEntryV1Endpoint } from "./webservices/delete-keychain-entry-endpoint-v1"; +import { HasKeychainEntryV1Endpoint } from "./webservices/has-keychain-entry-endpoint-v1"; export enum AwsCredentialType { LocalFile = "LOCAL_FILE", @@ -31,6 +36,8 @@ export enum AwsCredentialType { } export interface IPluginKeychainAwsSmOptions extends ICactusPluginOptions { + instanceId: string; + pluginRegistry: PluginRegistry; logLevel?: LogLevelDesc; keychainId: string; awsProfile: string; @@ -157,7 +164,24 @@ export class PluginKeychainAwsSm if (Array.isArray(this.endpoints)) { return this.endpoints; } - const endpoints: IWebServiceEndpoint[] = []; + const endpoints: IWebServiceEndpoint[] = [ + new SetKeychainEntryV1Endpoint({ + connector: this, + logLevel: this.opts.logLevel, + }), + new GetKeychainEntryV1Endpoint({ + connector: this, + logLevel: this.opts.logLevel, + }), + new DeleteKeychainEntryV1Endpoint({ + connector: this, + logLevel: this.opts.logLevel, + }), + new HasKeychainEntryV1Endpoint({ + connector: this, + logLevel: this.opts.logLevel, + }), + ]; this.endpoints = endpoints; @@ -210,7 +234,8 @@ export class PluginKeychainAwsSm ); if (errorStatus) { // FIXME: Throw if the value was not present instead of returning null - return (null as unknown) as string; + //return (null as unknown) as string; + throw new Error(`${key} secret not found`); } else { this.log.error(`Error retriving secret value for the key "${key}"`); throw ex; diff --git a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/public-api.ts b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/public-api.ts index c65964a920..f0687026a3 100644 --- a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/public-api.ts +++ b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/public-api.ts @@ -1,7 +1,9 @@ +export * from "./generated/openapi/typescript-axios/index"; + import { IPluginFactoryOptions } from "@hyperledger/cactus-core-api"; import { PluginFactoryKeychain } from "./plugin-factory-keychain"; -export { PluginFactoryKeychain } from "./plugin-factory-keychain"; +//export { PluginFactoryKeychain } from "./plugin-factory-keychain"; export { IPluginKeychainAwsSmOptions, diff --git a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/delete-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/delete-keychain-entry-endpoint-v1.ts new file mode 100644 index 0000000000..2c1743755c --- /dev/null +++ b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/delete-keychain-entry-endpoint-v1.ts @@ -0,0 +1,102 @@ +import type { Express, Request, Response } from "express"; + +import { + Logger, + Checks, + LogLevelDesc, + LoggerProvider, + IAsyncProvider, +} from "@hyperledger/cactus-common"; +import { + IEndpointAuthzOptions, + IExpressRequestHandler, + IWebServiceEndpoint, +} from "@hyperledger/cactus-core-api"; +import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; + +import OAS from "../../json/openapi.json"; +import { PluginKeychainAwsSm } from "../plugin-keychain-aws-sm"; +import { DeleteKeychainEntryRequestV1 } from "../generated/openapi/typescript-axios/api"; + +export interface IDeleteKeychainEntryEndpointOptions { + logLevel?: LogLevelDesc; + connector: PluginKeychainAwsSm; +} + +export class DeleteKeychainEntryV1Endpoint implements IWebServiceEndpoint { + public static readonly CLASS_NAME = "DeleteKeychainEntryV1Endpoint"; + + private readonly log: Logger; + + public get className(): string { + return DeleteKeychainEntryV1Endpoint.CLASS_NAME; + } + + constructor(public readonly options: IDeleteKeychainEntryEndpointOptions) { + const fnTag = `${this.className}#constructor()`; + Checks.truthy(options, `${fnTag} arg options`); + Checks.truthy(options.connector, `${fnTag} arg options.connector`); + + const level = this.options.logLevel || "INFO"; + const label = this.className; + this.log = LoggerProvider.getOrCreate({ level, label }); + } + + public getOasPath() { + return OAS.paths[ + "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-aws-sm/delete-keychain-entry" + ]; + } + + public getPath(): string { + const apiPath = this.getOasPath(); + return apiPath.post["x-hyperledger-cactus"].http.path; + } + + public getVerbLowerCase(): string { + const apiPath = this.getOasPath(); + return apiPath.post["x-hyperledger-cactus"].http.verbLowerCase; + } + + public getOperationId(): string { + return this.getOasPath().post.operationId; + } + + getAuthorizationOptionsProvider(): IAsyncProvider { + // TODO: make this an injectable dependency in the constructor + return { + get: async () => ({ + isProtected: true, + requiredRoles: [], + }), + }; + } + + public async registerExpress( + expressApp: Express, + ): Promise { + await registerWebServiceEndpoint(expressApp, this); + return this; + } + + public getExpressRequestHandler(): IExpressRequestHandler { + return this.handleRequest.bind(this); + } + + public async handleRequest(req: Request, res: Response): Promise { + const reqTag = `${this.getVerbLowerCase()} - ${this.getPath()}`; + this.log.debug(reqTag); + //const reqBody = req.body; + try { + const { key } = req.body as DeleteKeychainEntryRequestV1; + const resBody = await this.options.connector.delete(key); + res.json(resBody); + } catch (ex) { + this.log.error(`Crash while serving ${reqTag}`, ex); + res.status(500).json({ + message: "Internal Server Error", + error: ex?.stack || ex?.message, + }); + } + } +} diff --git a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/get-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/get-keychain-entry-endpoint-v1.ts index 9c3a8b5d6f..1a3f70036c 100644 --- a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/get-keychain-entry-endpoint-v1.ts +++ b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/get-keychain-entry-endpoint-v1.ts @@ -1,4 +1,4 @@ -import type { Express } from "express"; +import type { Express, Request, Response } from "express"; import { Logger, @@ -8,6 +8,7 @@ import { IAsyncProvider, } from "@hyperledger/cactus-common"; import { + GetKeychainEntryRequestV1, IEndpointAuthzOptions, IExpressRequestHandler, IWebServiceEndpoint, @@ -15,34 +16,50 @@ import { import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; +import { PluginKeychainAwsSm } from "../plugin-keychain-aws-sm"; -export interface IGetKeychainEntryEndpointV1Options { +export interface IGetKeychainEntryEndpointOptions { logLevel?: LogLevelDesc; + connector: PluginKeychainAwsSm; } -export class GetKeychainEntryEndpointV1 implements IWebServiceEndpoint { - public static readonly CLASS_NAME = "GetKeychainEntryEndpointV1"; +export class GetKeychainEntryV1Endpoint implements IWebServiceEndpoint { + public static readonly CLASS_NAME = "GetKeychainEntryV1Endpoint"; private readonly log: Logger; public get className(): string { - return GetKeychainEntryEndpointV1.CLASS_NAME; + return GetKeychainEntryV1Endpoint.CLASS_NAME; } - constructor(public readonly options: IGetKeychainEntryEndpointV1Options) { + constructor(public readonly options: IGetKeychainEntryEndpointOptions) { const fnTag = `${this.className}#constructor()`; Checks.truthy(options, `${fnTag} arg options`); + Checks.truthy(options.connector, `${fnTag} arg options.connector`); const level = this.options.logLevel || "INFO"; const label = this.className; this.log = LoggerProvider.getOrCreate({ level, label }); - this.log.debug(`Instantiated ${this.className} OK`); } - private getOperation() { + public getOasPath() { return OAS.paths[ "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-aws-sm/get-keychain-entry" - ].post; + ]; + } + + public getPath(): string { + const apiPath = this.getOasPath(); + return apiPath.post["x-hyperledger-cactus"].http.path; + } + + public getVerbLowerCase(): string { + const apiPath = this.getOasPath(); + return apiPath.post["x-hyperledger-cactus"].http.verbLowerCase; + } + + public getOperationId(): string { + return this.getOasPath().post.operationId; } getAuthorizationOptionsProvider(): IAsyncProvider { @@ -62,15 +79,32 @@ export class GetKeychainEntryEndpointV1 implements IWebServiceEndpoint { return this; } - public getVerbLowerCase(): string { - return this.getOperation()["x-hyperledger-cactus"].http.verbLowerCase; - } - - public getPath(): string { - return this.getOperation()["x-hyperledger-cactus"].http.path; + public getExpressRequestHandler(): IExpressRequestHandler { + return this.handleRequest.bind(this); } - public getExpressRequestHandler(): IExpressRequestHandler { - throw new Error("Method not implemented."); + public async handleRequest(req: Request, res: Response): Promise { + const reqTag = `${this.getVerbLowerCase()} - ${this.getPath()}`; + this.log.debug(reqTag); + const { key } = req.body as GetKeychainEntryRequestV1; + //const reqBody = req.body; + try { + const value = await this.options.connector.get(key); + //const resBody = await this.options.connector.get(reqBody.key); + res.json({ key, value }); + } catch (ex) { + if (ex?.message?.includes(`${key} secret not found`)) { + res.status(404).json({ + key, + error: ex?.stack || ex?.message, + }); + } else { + this.log.error(`Crash while serving ${reqTag}`, ex); + res.status(500).json({ + message: "Internal Server Error", + error: ex?.stack || ex?.message, + }); + } + } } } diff --git a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/has-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/has-keychain-entry-endpoint-v1.ts new file mode 100644 index 0000000000..20b34bdb36 --- /dev/null +++ b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/has-keychain-entry-endpoint-v1.ts @@ -0,0 +1,108 @@ +import type { Express, Request, Response } from "express"; + +import { + Logger, + Checks, + LogLevelDesc, + LoggerProvider, + IAsyncProvider, +} from "@hyperledger/cactus-common"; +import { + IEndpointAuthzOptions, + IExpressRequestHandler, + IWebServiceEndpoint, +} from "@hyperledger/cactus-core-api"; +import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; + +import OAS from "../../json/openapi.json"; +import { PluginKeychainAwsSm } from "../plugin-keychain-aws-sm"; +import { HasKeychainEntryRequestV1 } from "../generated/openapi/typescript-axios/api"; + +export interface IHasKeychainEntryEndpointOptions { + logLevel?: LogLevelDesc; + connector: PluginKeychainAwsSm; +} + +export class HasKeychainEntryV1Endpoint implements IWebServiceEndpoint { + public static readonly CLASS_NAME = "HasKeychainEntryV1Endpoint"; + + private readonly log: Logger; + + public get className(): string { + return HasKeychainEntryV1Endpoint.CLASS_NAME; + } + + constructor(public readonly options: IHasKeychainEntryEndpointOptions) { + const fnTag = `${this.className}#constructor()`; + Checks.truthy(options, `${fnTag} arg options`); + Checks.truthy(options.connector, `${fnTag} arg options.connector`); + + const level = this.options.logLevel || "INFO"; + const label = this.className; + this.log = LoggerProvider.getOrCreate({ level, label }); + } + + public getOasPath() { + return OAS.paths[ + "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-aws-sm/has-keychain-entry" + ]; + } + + public getPath(): string { + const apiPath = this.getOasPath(); + return apiPath.post["x-hyperledger-cactus"].http.path; + } + + public getVerbLowerCase(): string { + const apiPath = this.getOasPath(); + return apiPath.post["x-hyperledger-cactus"].http.verbLowerCase; + } + + public getOperationId(): string { + return this.getOasPath().post.operationId; + } + + getAuthorizationOptionsProvider(): IAsyncProvider { + // TODO: make this an injectable dependency in the constructor + return { + get: async () => ({ + isProtected: true, + requiredRoles: [], + }), + }; + } + + public async registerExpress( + expressApp: Express, + ): Promise { + await registerWebServiceEndpoint(expressApp, this); + return this; + } + + public getExpressRequestHandler(): IExpressRequestHandler { + return this.handleRequest.bind(this); + } + + public async handleRequest(req: Request, res: Response): Promise { + const reqTag = `${this.getVerbLowerCase()} - ${this.getPath()}`; + this.log.debug(reqTag); + try { + const reqBody = req.body as HasKeychainEntryRequestV1; + const { key } = reqBody; + const checkedAt = new Date().toJSON(); + const isPresent = await this.options.connector.has(key); + const resBody = { + isPresent, + key, + checkedAt, + }; + res.json(resBody); + } catch (ex) { + this.log.error(`Crash while serving ${reqTag}`, ex); + res.status(500).json({ + message: "Internal Server Error", + error: ex?.stack || ex?.message, + }); + } + } +} diff --git a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/set-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/set-keychain-entry-endpoint-v1.ts index 6c3514e42b..7f6608d9d7 100644 --- a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/set-keychain-entry-endpoint-v1.ts +++ b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/set-keychain-entry-endpoint-v1.ts @@ -1,4 +1,4 @@ -import type { Express } from "express"; +import type { Express, Request, Response } from "express"; import { Logger, @@ -15,34 +15,51 @@ import { import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; +import { PluginKeychainAwsSm } from "../plugin-keychain-aws-sm"; +import { SetKeychainEntryRequest } from "../generated/openapi/typescript-axios/api"; -export interface ISetKeychainEntryEndpointV1Options { +export interface ISetKeychainEntryEndpointOptions { logLevel?: LogLevelDesc; + connector: PluginKeychainAwsSm; } -export class SetKeychainEntryEndpointV1 implements IWebServiceEndpoint { - public static readonly CLASS_NAME = "SetKeychainEntryEndpointV1"; +export class SetKeychainEntryV1Endpoint implements IWebServiceEndpoint { + public static readonly CLASS_NAME = "SetKeychainEntryV1Endpoint"; private readonly log: Logger; public get className(): string { - return SetKeychainEntryEndpointV1.CLASS_NAME; + return SetKeychainEntryV1Endpoint.CLASS_NAME; } - constructor(public readonly options: ISetKeychainEntryEndpointV1Options) { + constructor(public readonly options: ISetKeychainEntryEndpointOptions) { const fnTag = `${this.className}#constructor()`; Checks.truthy(options, `${fnTag} arg options`); + Checks.truthy(options.connector, `${fnTag} arg options.connector`); const level = this.options.logLevel || "INFO"; const label = this.className; this.log = LoggerProvider.getOrCreate({ level, label }); - this.log.debug(`Instantiated ${this.className} OK`); } - private getOperation() { + public getOasPath() { return OAS.paths[ "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-aws-sm/set-keychain-entry" - ].post; + ]; + } + + public getPath(): string { + const apiPath = this.getOasPath(); + return apiPath.post["x-hyperledger-cactus"].http.path; + } + + public getVerbLowerCase(): string { + const apiPath = this.getOasPath(); + return apiPath.post["x-hyperledger-cactus"].http.verbLowerCase; + } + + public getOperationId(): string { + return this.getOasPath().post.operationId; } getAuthorizationOptionsProvider(): IAsyncProvider { @@ -62,15 +79,23 @@ export class SetKeychainEntryEndpointV1 implements IWebServiceEndpoint { return this; } - public getVerbLowerCase(): string { - return this.getOperation()["x-hyperledger-cactus"].http.verbLowerCase; - } - - public getPath(): string { - return this.getOperation()["x-hyperledger-cactus"].http.path; + public getExpressRequestHandler(): IExpressRequestHandler { + return this.handleRequest.bind(this); } - public getExpressRequestHandler(): IExpressRequestHandler { - throw new Error("Method not implemented."); + public async handleRequest(req: Request, res: Response): Promise { + const reqTag = `${this.getVerbLowerCase()} - ${this.getPath()}`; + this.log.debug(reqTag); + try { + const { key, value } = req.body as SetKeychainEntryRequest; + const resBody = await this.options.connector.set(key, value); + res.json(resBody); + } catch (ex) { + this.log.error(`Crash while serving ${reqTag}`, ex); + res.status(500).json({ + message: "Internal Server Error", + error: ex?.stack || ex?.message, + }); + } } } diff --git a/packages/cactus-plugin-keychain-aws-sm/src/test/typescript/integration/plugin-factory-keychain.test.ts b/packages/cactus-plugin-keychain-aws-sm/src/test/typescript/integration/plugin-factory-keychain.test.ts new file mode 100644 index 0000000000..0aa566788d --- /dev/null +++ b/packages/cactus-plugin-keychain-aws-sm/src/test/typescript/integration/plugin-factory-keychain.test.ts @@ -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 { + AwsCredentialType, + PluginKeychainAwsSm, +} from "../../../main/typescript/plugin-keychain-aws-sm"; +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 iPluginKeychainAwsSmOptions = { + pluginRegistry, + instanceId: uuidv4(), + keychainId: uuidv4(), + logLevel: "TRACE", + awsProfile: "true", + awsRegion: "true", + awsEndpoint: "true", + awsAccessKeyId: "true", + awsSecretAccessKey: "true", + awsCredentialType: AwsCredentialType.InMemory, + }; + + const pluginFactoryKeychain1 = new PluginFactoryKeychain( + iPluginFactoryOptions1, + ); + + const pluginFactoryKeychain3 = new PluginFactoryKeychain(invalid); + + const pluginKeychainAwsSm = await pluginFactoryKeychain1.create( + iPluginKeychainAwsSmOptions, + ); + + t.true( + pluginKeychainAwsSm instanceof PluginKeychainAwsSm, + "pluginImportType.Local results in pluginKeychainAwsSm", + ); + + await t.rejects( + pluginFactoryKeychain3.create({ + invalid, + }), + ); + + t.end(); +}); diff --git a/packages/cactus-plugin-keychain-aws-sm/src/test/typescript/integration/plugin-keychain-aws-sm.test.ts b/packages/cactus-plugin-keychain-aws-sm/src/test/typescript/integration/plugin-keychain-aws-sm.test.ts index 97b521f5a4..75102f4c6f 100644 --- a/packages/cactus-plugin-keychain-aws-sm/src/test/typescript/integration/plugin-keychain-aws-sm.test.ts +++ b/packages/cactus-plugin-keychain-aws-sm/src/test/typescript/integration/plugin-keychain-aws-sm.test.ts @@ -1,6 +1,13 @@ import test, { Test } from "tape-promise/tape"; -import { v4 as internalIpV4 } from "internal-ip"; +import express from "express"; +import bodyParser from "body-parser"; +import http from "http"; +import { AddressInfo } from "net"; + +import { IListenOptions, Servers } from "@hyperledger/cactus-common"; + +import { v4 as internalIpV4 } from "internal-ip"; import { Containers, LocalStackContainer, @@ -17,9 +24,15 @@ import { AwsCredentialType, } from "../../../main/typescript/public-api"; +import { + DefaultApi as KeychainAwsSmApi, + Configuration, +} from "../../../main/typescript/generated/openapi/typescript-axios/index"; + import fs from "fs"; import path from "path"; import os from "os"; +import { PluginRegistry } from "@hyperledger/cactus-core"; const logLevel: LogLevelDesc = "TRACE"; @@ -56,6 +69,7 @@ test("get,set,has,delete alters state as expected", async (t: Test) => { const options1: IPluginKeychainAwsSmOptions = { instanceId: uuidv4(), keychainId: uuidv4(), + pluginRegistry: new PluginRegistry({}), awsEndpoint: localstackHost, awsRegion: "us-east-1", awsProfile: "default", @@ -65,82 +79,95 @@ test("get,set,has,delete alters state as expected", async (t: Test) => { }; const plugin1 = new PluginKeychainAwsSm(options1); - t.equal(plugin1.getKeychainId(), options1.keychainId, "Keychain ID set OK"); - t.equal(plugin1.getInstanceId(), options1.instanceId, "Instance ID set OK"); - - const key1 = uuidv4(); - const value1 = uuidv4(); - - const hasPrior1 = await plugin1.has(key1); - - t.false(hasPrior1, "hasPrior1 === false OK"); - - await plugin1.set(key1, value1); - - const hasAfter1 = await plugin1.has(key1); - t.true(hasAfter1, "hasAfter1 === true OK"); - - const valueAfter1 = await plugin1.get(key1); - t.ok(valueAfter1, "valueAfter1 truthy OK"); - t.equal(valueAfter1, value1, "valueAfter1 === value OK"); - - await plugin1.delete(key1); - - const hasAfterDelete1 = await plugin1.has(key1); - t.false(hasAfterDelete1, "hasAfterDelete1 === false OK"); - - const valueAfterDelete1 = await plugin1.get(key1); - t.notok(valueAfterDelete1, "valueAfterDelete1 falsy OK"); - - await (async () => { - await fs.promises.unlink(`${tmpDirPath}/credentials`); - await fs.promises.rmdir(`${tmpDirPath}`); - })(); - } - - // Using awsCredentialType: AwsCredentialType.FromCodeVariable - // Test for AWS access credentials cannot be performed over Localstack, as the opensourced version of it - // doesn't support AWS IAM authentication. - { - const options2: IPluginKeychainAwsSmOptions = { - instanceId: uuidv4(), - keychainId: uuidv4(), - awsEndpoint: localstackHost, - awsRegion: "us-east-1", - awsProfile: "default", - awsCredentialType: AwsCredentialType.InMemory, - awsAccessKeyId: "fake", - awsSecretAccessKey: "fake", - logLevel: logLevel, + const expressApp = express(); + expressApp.use(bodyParser.json({ limit: "250mb" })); + const server = http.createServer(expressApp); + const listenOptions: IListenOptions = { + hostname: "0.0.0.0", + port: 0, + server, }; - const plugin2 = new PluginKeychainAwsSm(options2); + const addressInfo = (await Servers.listen(listenOptions)) as AddressInfo; + test.onFinish(async () => await Servers.shutdown(server)); + const { address, port } = addressInfo; + const apiHost = `http://${address}:${port}`; + const config = new Configuration({ basePath: apiHost }); + const apiClient = new KeychainAwsSmApi(config); - t.equal(plugin2.getKeychainId(), options2.keychainId, "Keychain ID set OK"); - t.equal(plugin2.getInstanceId(), options2.instanceId, "Instance ID set OK"); + await plugin1.registerWebServices(expressApp); - const key2 = uuidv4(); - const value2 = uuidv4(); - - const hasPrior2 = await plugin2.has(key2); - - t.false(hasPrior2, "hasPrior2 === false OK"); - - await plugin2.set(key2, value2); - - const hasAfter2 = await plugin2.has(key2); - t.true(hasAfter2, "hasAfter2 === true OK"); - - const valueAfter2 = await plugin2.get(key2); - t.ok(valueAfter2, "valueAfter2 truthy OK"); - t.equal(valueAfter2, value2, "valueAfter2 === value OK"); - - await plugin2.delete(key2); - - const hasAfterDelete2 = await plugin2.has(key2); - t.false(hasAfterDelete2, "hasAfterDelete2 === false OK"); + t.equal(plugin1.getKeychainId(), options1.keychainId, "Keychain ID set OK"); + t.equal(plugin1.getInstanceId(), options1.instanceId, "Instance ID set OK"); - const valueAfterDelete2 = await plugin2.get(key2); - t.notok(valueAfterDelete2, "valueAfterDelete2 falsy OK"); + const key = uuidv4(); + const value = uuidv4(); + + //const hasPrior1 = await plugin1.has(key1); + //t.false(hasPrior1, "hasPrior1 === false OK"); + + const res1 = await apiClient.hasKeychainEntryV1({ key }); + t.true(res1.status >= 200, "res1.status >= 200 OK"); + t.true(res1.status < 300, "res1.status < 300"); + + t.ok(res1.data, "res1.data truthy OK"); + t.false(res1.data.isPresent, "res1.data.isPresent === false OK"); + t.ok(res1.data.checkedAt, "res1.data.checkedAt truthy OK"); + t.equal(res1.data.key, key, "res1.data.key === key OK"); + + const res2 = await apiClient.setKeychainEntryV1({ + key: key, + value: value, + }); + t.true(res2.status >= 200, "res2.status >= 200 OK"); + t.true(res2.status < 300, "res2.status < 300 OK"); + t.notOk(res2.data, "res2.data truthy OK"); + + const res3 = await apiClient.hasKeychainEntryV1({ key }); + t.true(res3.status >= 200, "res3.status >= 200 OK"); + t.true(res3.status < 300, "res3.status < 300 OK"); + t.ok(res3.data, "res3.data truthy OK"); + t.true(res3.data.isPresent, "res3.data.isPresent === true OK"); + t.ok(res3.data.checkedAt, "res3.data.checkedAt truthy OK"); + t.equal(res3.data.key, key, "res3.data.key === key OK"); + + const res4 = await apiClient.getKeychainEntryV1({ + key: key, + }); + t.true(res4.status >= 200, "res4.status >= 200 OK"); + t.true(res4.status < 300, "res4.status < 300 OK"); + t.ok(res4.data, "res4.data truthy OK"); + t.equal(res4.data.value, value, "res4.data.value === value OK"); + + const res5 = await apiClient.deleteKeychainEntryV1({ key }); + t.true(res5.status >= 200, "res5.status >= 200 OK"); + t.true(res5.status < 300, "res5.status < 300 OK"); + t.notOk(res5.data, "res5.data falsy OK"); + + const res6 = await apiClient.hasKeychainEntryV1({ key }); + t.true(res6.status >= 200, "res6.status >= 200 OK"); + t.true(res6.status < 300, "res6.status < 300 OK"); + t.ok(res6.data, "res6.data truthy OK"); + t.false(res6.data.isPresent, "res6.data.isPresent === false OK"); + t.ok(res6.data.checkedAt, "res6.data.checkedAt truthy OK"); + t.equal(res6.data.key, key, "res6.data.key === key OK"); + + try { + await apiClient.getKeychainEntryV1({ key }); + t.fail( + "Failing because getKeychainEntryV1 did not throw when called with non-existent key.", + ); + } catch (ex) { + t.ok(ex, "res7 -> ex truthy"); + const res7 = ex.response; + t.equal(res7.status, 404, "res7.status === 404 OK"); + t.ok(res7.data, "res7.data truthy OK"); + t.ok(res7.data.error, "res7.data.error truthy OK"); + t.equal(typeof res7.data.error, "string", "res7.data.error truthy OK"); + t.true( + res7.data.error.includes(`${key} secret not found`), + "res7.data.error contains legible error message about missing key OK", + ); + } } t.end(); diff --git a/packages/cactus-plugin-keychain-aws-sm/tsconfig.json b/packages/cactus-plugin-keychain-aws-sm/tsconfig.json index 2542d2a1fb..18e531e90a 100644 --- a/packages/cactus-plugin-keychain-aws-sm/tsconfig.json +++ b/packages/cactus-plugin-keychain-aws-sm/tsconfig.json @@ -25,4 +25,4 @@ "path": "../cactus-test-tooling/tsconfig.json" } ] -} \ No newline at end of file +} diff --git a/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-balance-endpoint.test.ts b/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-balance-endpoint.test.ts index 8255b4e650..c6574de688 100644 --- a/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-balance-endpoint.test.ts +++ b/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-balance-endpoint.test.ts @@ -157,7 +157,6 @@ test(testCase, async (t: Test) => { */ const request: GetBalanceV1Request = { - //is it suppose to be GetBalanceV1Request? address: testAccount.address, };