From 5fa034274578daec227ee073a23ceff59028b7b3 Mon Sep 17 00:00:00 2001 From: Youngone Lee Date: Wed, 1 Sep 2021 15:32:59 -0500 Subject: [PATCH] feat(keychain-aws-sm): complete request handler and endpoint Fixes #967 Depends on #1349 Signed-off-by: Youngone Lee --- package.json | 5 +- .../src/main/json/openapi.json | 142 +++++------ .../generated/openapi/typescript-axios/api.ts | 36 +-- .../src/main/json/openapi.json | 88 +++++-- .../generated/openapi/typescript-axios/api.ts | 234 ++++++++++++++++-- .../typescript/plugin-factory-keychain.ts | 30 +-- .../main/typescript/plugin-keychain-aws-sm.ts | 29 ++- .../src/main/typescript/public-api.ts | 4 +- .../delete-keychain-entry-endpoint-v1.ts | 102 ++++++++ .../get-keychain-entry-endpoint-v1.ts | 68 +++-- .../has-keychain-entry-endpoint-v1.ts | 108 ++++++++ .../set-keychain-entry-endpoint-v1.ts | 59 +++-- .../plugin-factory-keychain.test.ts | 59 +++++ .../plugin-keychain-aws-sm.test.ts | 173 +++++++------ .../tsconfig.json | 2 +- .../src/main/json/openapi.json | 31 ++- .../generated/openapi/typescript-axios/api.ts | 88 +++---- .../get-keychain-entry-endpoint-v1.ts | 4 +- .../get-balance-endpoint.test.ts | 1 - 19 files changed, 959 insertions(+), 304 deletions(-) create mode 100644 packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/delete-keychain-entry-endpoint-v1.ts create mode 100644 packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/has-keychain-entry-endpoint-v1.ts create mode 100644 packages/cactus-plugin-keychain-aws-sm/src/test/typescript/integration/plugin-factory-keychain.test.ts diff --git a/package.json b/package.json index d107e11cfad..de2bf3732d6 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,10 @@ }, "scripts": { "run-ci": "./tools/ci.sh", - "reset": "git clean -f -X && yarn run configure", + "reset:node-modules": "del-cli --dry-run '**/node_modules'", + "reset:git": "git clean -f -X", + "reset:yarn-lock": "del-cli yarn.lock && yarn install --update-checksums --force", + "reset": "run-s reset:git reset:node-modules reset:yarn-lock configure", "configure": "yarn install --frozen-lockfile --non-interactive && yarn run build:dev:backend", "install-yarn": "npm install --global yarn@1.19.0", "custom-checks": "TS_NODE_PROJECT=./tools/tsconfig.json node --trace-deprecation --experimental-modules --abort-on-uncaught-exception --loader ts-node/esm --experimental-specifier-resolution=node ./tools/custom-checks/run-custom-checks.ts", diff --git a/packages/cactus-core-api/src/main/json/openapi.json b/packages/cactus-core-api/src/main/json/openapi.json index db0306f21be..b4d4d089dc2 100644 --- a/packages/cactus-core-api/src/main/json/openapi.json +++ b/packages/cactus-core-api/src/main/json/openapi.json @@ -522,7 +522,7 @@ } } }, - "GetKeychainEntryRequest": { + "GetKeychainEntryRequestV1": { "type": "object", "required": [ "key" @@ -530,38 +530,30 @@ "properties": { "key": { "type": "string", - "description": "The key for the entry to get from the keychain.", + "description": "The key for the entry to delete from the keychain.", "minLength": 1, "maxLength": 1024, "nullable": false } } }, - "GetKeychainEntryResponse": { + "DeleteKeychainEntryRequestV1": { "type": "object", "required": [ - "key", - "value" + "key" ], "additionalProperties": false, "properties": { "key": { "type": "string", - "description": "The key that was used to retrieve the value from the keychain.", + "description": "The key for the entry to get from the keychain.", "minLength": 1, "maxLength": 1024, "nullable": false - }, - "value": { - "type": "string", - "description": "The value associated with the requested key on the keychain.", - "minLength": 0, - "maxLength": 10485760, - "nullable": false } } }, - "SetKeychainEntryRequest": { + "GetKeychainEntryResponseV1": { "type": "object", "required": [ "key", @@ -571,51 +563,44 @@ "properties": { "key": { "type": "string", - "description": "The key for the entry to set on the keychain.", + "description": "The key that was used to retrieve the value from the keychain.", "minLength": 1, "maxLength": 1024, "nullable": false }, "value": { "type": "string", - "description": "The value that will be associated with the key on the keychain.", + "description": "The value associated with the requested key on the keychain.", "minLength": 0, "maxLength": 10485760, "nullable": false } } }, - "SetKeychainEntryResponse": { + "SetKeychainEntryRequestV1": { "type": "object", "required": [ - "key" + "key", + "value" ], "properties": { "key": { "type": "string", - "description": "The key that was used to set the value on the keychain.", + "description": "The key for the entry to check on the keychain.", "minLength": 1, "maxLength": 1024, "nullable": false - } - } - }, - "DeleteKeychainEntryRequestV1": { - "type": "object", - "required": [ - "key" - ], - "properties": { - "key": { + }, + "value": { "type": "string", - "description": "The key for the entry to check the presence of on the keychain.", - "minLength": 1, - "maxLength": 1024, + "description": "The value that will be associated with the key on the keychain.", + "minLength": 0, + "maxLength": 10485760, "nullable": false } } }, - "DeleteKeychainEntryResponseV1": { + "SetKeychainEntryResponseV1": { "type": "object", "required": [ "key" @@ -624,13 +609,13 @@ "properties": { "key": { "type": "string", - "description": "The key that was deleted from the keychain.", + "description": "The key that was used to set the value on the keychain.", "minLength": 1, "maxLength": 1024, "nullable": false } } - }, + }, "HasKeychainEntryRequestV1": { "type": "object", "required": [ @@ -640,7 +625,7 @@ "properties": { "key": { "type": "string", - "description": "The key to check for presence in the keychain.", + "description": "The key to check for presence in the keychain", "minLength": 1, "maxLength": 1024, "nullable": false @@ -669,6 +654,21 @@ "nullable": false } } + }, + "DeleteKeychainEntryResponseV1": { + "type": "object", + "required": [ + "key" + ], + "properties": { + "key": { + "type": "string", + "description": "The key that was deleted from the keychain.", + "minLength": 1, + "maxLength": 1024, + "nullable": false + } + } } }, "requestBodies": { @@ -711,7 +711,7 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/GetKeychainEntryRequest" + "$ref": "#/components/schemas/GetKeychainEntryRequestV1" } } } @@ -722,29 +722,29 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/SetKeychainEntryRequest" + "$ref": "#/components/schemas/SetKeychainEntryRequestV1" } } } - }, - "keychain_has_entry_request_body": { - "description": "Request body for checking a keychain entry via its key", + }, + "keychain_delete_entry_request_body": { + "description": "Request body to delete a keychain entry via its key", "required": true, "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/HasKeychainEntryRequestV1" + "$ref": "#/components/schemas/DeleteKeychainEntryRequestV1" } } } - }, - "keychain_delete_entry_request_body": { - "description": "Request body to delete a keychain entry via its key", + }, + "keychain_has_entry_request_body": { + "description": "Request body for checking a keychain entry via its key", "required": true, "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/DeleteKeychainEntryRequestV1" + "$ref": "#/components/schemas/HasKeychainEntryRequestV1" } } } @@ -784,11 +784,11 @@ "keychain_get_entry_200": { "description": "OK", "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/GetKeychainEntryResponse" - } - } + "application/json": { + "schema": { + "$ref": "#/components/schemas/GetKeychainEntryResponseV1" + } + } } }, "keychain_get_entry_400": { @@ -807,9 +807,9 @@ "description": "OK", "content": { "application/json": { - "schema": { - "$ref": "#/components/schemas/SetKeychainEntryResponse" - } + "schema": { + "$ref": "#/components/schemas/SetKeychainEntryResponseV1" + } } } }, @@ -822,42 +822,42 @@ "keychain_set_entry_500": { "description": "Unexpected error." }, - "keychain_has_entry_200": { + "keychain_delete_entry_200": { "description": "OK", "content": { "application/json": { - "schema": { - "$ref": "#/components/schemas/HasKeychainEntryResponseV1" - } + "schema": { + "$ref": "#/components/schemas/DeleteKeychainEntryResponseV1" + } } - } + } }, - "keychain_has_entry_400": { + "keychain_delete_entry_400": { "description": "Bad request. Key must be a string and longer than 0, shorter than 1024 characters." }, - "keychain_has_entry_401": { + "keychain_delete_entry_401": { "description": "Authorization information is missing or invalid." }, - "keychain_has_entry_500": { + "keychain_delete_entry_500": { "description": "Unexpected error." - }, - "keychain_delete_entry_200": { + }, + "keychain_has_entry_200": { "description": "OK", "content": { "application/json": { - "schema": { - "$ref": "#/components/schemas/DeleteKeychainEntryResponseV1" - } + "schema": { + "$ref": "#/components/schemas/HasKeychainEntryResponseV1" + } } - } + } }, - "keychain_delete_entry_400": { + "keychain_has_entry_400": { "description": "Bad request. Key must be a string and longer than 0, shorter than 1024 characters." }, - "keychain_delete_entry_401": { + "keychain_has_entry_401": { "description": "Authorization information is missing or invalid." }, - "keychain_delete_entry_500": { + "keychain_has_entry_500": { "description": "Unexpected error." } } diff --git a/packages/cactus-core-api/src/main/typescript/generated/openapi/typescript-axios/api.ts b/packages/cactus-core-api/src/main/typescript/generated/openapi/typescript-axios/api.ts index ac5f44df4cd..045339b19e1 100644 --- a/packages/cactus-core-api/src/main/typescript/generated/openapi/typescript-axios/api.ts +++ b/packages/cactus-core-api/src/main/typescript/generated/openapi/typescript-axios/api.ts @@ -269,7 +269,7 @@ export enum Constants { */ export interface DeleteKeychainEntryRequestV1 { /** - * The key for the entry to check the presence of on the keychain. + * The key for the entry to get from the keychain. * @type {string} * @memberof DeleteKeychainEntryRequestV1 */ @@ -291,32 +291,32 @@ export interface DeleteKeychainEntryResponseV1 { /** * * @export - * @interface GetKeychainEntryRequest + * @interface GetKeychainEntryRequestV1 */ -export interface GetKeychainEntryRequest { +export interface GetKeychainEntryRequestV1 { /** - * The key for the entry to get from the keychain. + * The key for the entry to delete from the keychain. * @type {string} - * @memberof GetKeychainEntryRequest + * @memberof GetKeychainEntryRequestV1 */ key: string; } /** * * @export - * @interface GetKeychainEntryResponse + * @interface GetKeychainEntryResponseV1 */ -export interface GetKeychainEntryResponse { +export interface GetKeychainEntryResponseV1 { /** * The key that was used to retrieve the value from the keychain. * @type {string} - * @memberof GetKeychainEntryResponse + * @memberof GetKeychainEntryResponseV1 */ key: string; /** * The value associated with the requested key on the keychain. * @type {string} - * @memberof GetKeychainEntryResponse + * @memberof GetKeychainEntryResponseV1 */ value: string; } @@ -359,7 +359,7 @@ export interface GetObjectResponseV1 { */ export interface HasKeychainEntryRequestV1 { /** - * The key to check for presence in the keychain. + * The key to check for presence in the keychain * @type {string} * @memberof HasKeychainEntryRequestV1 */ @@ -572,32 +572,32 @@ export interface PluginInstance { /** * * @export - * @interface SetKeychainEntryRequest + * @interface SetKeychainEntryRequestV1 */ -export interface SetKeychainEntryRequest { +export interface SetKeychainEntryRequestV1 { /** - * The key for the entry to set on the keychain. + * The key for the entry to check on the keychain. * @type {string} - * @memberof SetKeychainEntryRequest + * @memberof SetKeychainEntryRequestV1 */ key: string; /** * The value that will be associated with the key on the keychain. * @type {string} - * @memberof SetKeychainEntryRequest + * @memberof SetKeychainEntryRequestV1 */ value: string; } /** * * @export - * @interface SetKeychainEntryResponse + * @interface SetKeychainEntryResponseV1 */ -export interface SetKeychainEntryResponse { +export interface SetKeychainEntryResponseV1 { /** * The key that was used to set the value on the keychain. * @type {string} - * @memberof SetKeychainEntryResponse + * @memberof SetKeychainEntryResponseV1 */ key: string; } 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 344be779f03..c40f6ee9938 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,27 +31,27 @@ "verbLowerCase": "post" } }, - "operationId": "getKeychainEntry", + "operationId": "getKeychainEntryV1", "summary": "Retrieves the contents of a keychain entry from the backend.", "parameters": [], "requestBody": { - "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.8.0/packages/cactus-core-api/src/main/json/openapi.json#/components/requestBodies/keychain_get_entry_request_body" + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.9.0/packages/cactus-core-api/src/main/json/openapi.json#/components/requestBodies/keychain_get_entry_request_body" }, "responses": { "200": { - "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.8.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_200" + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.9.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_200" }, "400": { - "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.8.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_400" + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.9.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_400" }, "401": { - "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.8.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_401" + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.9.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_401" }, "404": { - "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.8.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_404" + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.9.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_404" }, "500": { - "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.8.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_500" + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.9.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_500" } } } @@ -64,27 +64,87 @@ "verbLowerCase": "post" } }, - "operationId": "setKeychainEntry", + "operationId": "setKeychainEntryV1", "summary": "Sets a value under a key on the keychain backend.", "parameters": [], "requestBody": { - "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.8.0/packages/cactus-core-api/src/main/json/openapi.json#/components/requestBodies/keychain_set_entry_request_body" + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.9.0/packages/cactus-core-api/src/main/json/openapi.json#/components/requestBodies/keychain_set_entry_request_body" }, "responses": { "200": { - "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.8.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_set_entry_200" + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.9.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_set_entry_200" }, "400": { - "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.8.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_set_entry_400" + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.9.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_set_entry_400" }, "401": { - "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.8.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_set_entry_401" + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.9.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_set_entry_401" }, "500": { - "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.8.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_set_entry_500" + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.9.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_set_entry_500" + } + } + } + }, + "/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 6c76cab18d9..5aa7e367979 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 dae3179d043..dcb24939195 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 0e52733713a..e73d4ca77c0 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 @@ -28,6 +28,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", @@ -35,6 +40,8 @@ export enum AwsCredentialType { } export interface IPluginKeychainAwsSmOptions extends ICactusPluginOptions { + instanceId: string; + pluginRegistry: PluginRegistry; logLevel?: LogLevelDesc; keychainId: string; awsProfile: string; @@ -161,7 +168,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; @@ -222,7 +246,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 c65964a920e..f0687026a38 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 00000000000..2c1743755c3 --- /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 9c3a8b5d6f7..9bac6853571 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, @@ -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 { GetKeychainEntryRequest } from "../generated/openapi/typescript-axios/api"; -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 GetKeychainEntryRequest; + //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 00000000000..20b34bdb368 --- /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 6c3514e42b0..7f6608d9d79 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 00000000000..0aa566788d3 --- /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 97b521f5a4d..75102f4c6f3 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 2542d2a1fbe..18e531e90a2 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-plugin-keychain-vault/src/main/json/openapi.json b/packages/cactus-plugin-keychain-vault/src/main/json/openapi.json index a63e8f8b5f9..d35b4d1b42a 100644 --- a/packages/cactus-plugin-keychain-vault/src/main/json/openapi.json +++ b/packages/cactus-plugin-keychain-vault/src/main/json/openapi.json @@ -94,23 +94,23 @@ "summary": "Retrieves the contents of a keychain entry from the backend.", "parameters": [], "requestBody": { - "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.5.0/packages/cactus-core-api/src/main/json/openapi.json#/components/requestBodies/keychain_get_entry_request_body" + "$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/requestBodies/keychain_get_entry_request_body" }, "responses": { "200": { - "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.5.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_200" + "$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_200" }, "400": { - "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.5.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_400" + "$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_400" }, "401": { - "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.5.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_401" + "$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_401" }, "404": { - "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.5.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_404" + "$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_404" }, "500": { - "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.5.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_500" + "$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_500" } } } @@ -145,6 +145,15 @@ } } } + }, + "400": { + "$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_400" + }, + "401": { + "$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_401" + }, + "500": { + "$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_500" } } } @@ -195,20 +204,20 @@ "summary": "Sets a value under a key on the keychain backend.", "parameters": [], "requestBody": { - "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.5.0/packages/cactus-core-api/src/main/json/openapi.json#/components/requestBodies/keychain_set_entry_request_body" + "$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/requestBodies/keychain_set_entry_request_body" }, "responses": { "200": { - "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.5.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_set_entry_200" + "$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_set_entry_200" }, "400": { - "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.5.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_set_entry_400" + "$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_set_entry_400" }, "401": { - "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.5.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_set_entry_401" + "$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_set_entry_401" }, "500": { - "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v0.5.0/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_set_entry_500" + "$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_set_entry_500" } } } diff --git a/packages/cactus-plugin-keychain-vault/src/main/typescript/generated/openapi/typescript-axios/api.ts b/packages/cactus-plugin-keychain-vault/src/main/typescript/generated/openapi/typescript-axios/api.ts index e1cf69fa488..b98f8439d71 100644 --- a/packages/cactus-plugin-keychain-vault/src/main/typescript/generated/openapi/typescript-axios/api.ts +++ b/packages/cactus-plugin-keychain-vault/src/main/typescript/generated/openapi/typescript-axios/api.ts @@ -50,32 +50,32 @@ export interface DeleteKeychainEntryResponseV1 { /** * * @export - * @interface GetKeychainEntryRequest + * @interface GetKeychainEntryRequestV1 */ -export interface GetKeychainEntryRequest { +export interface GetKeychainEntryRequestV1 { /** - * The key for the entry to get from the keychain. + * The key for the entry to delete from the keychain. * @type {string} - * @memberof GetKeychainEntryRequest + * @memberof GetKeychainEntryRequestV1 */ key: string; } /** * * @export - * @interface GetKeychainEntryResponse + * @interface GetKeychainEntryResponseV1 */ -export interface GetKeychainEntryResponse { +export interface GetKeychainEntryResponseV1 { /** * The key that was used to retrieve the value from the keychain. * @type {string} - * @memberof GetKeychainEntryResponse + * @memberof GetKeychainEntryResponseV1 */ key: string; /** * The value associated with the requested key on the keychain. * @type {string} - * @memberof GetKeychainEntryResponse + * @memberof GetKeychainEntryResponseV1 */ value: string; } @@ -120,32 +120,32 @@ export interface HasKeychainEntryResponseV1 { /** * * @export - * @interface SetKeychainEntryRequest + * @interface SetKeychainEntryRequestV1 */ -export interface SetKeychainEntryRequest { +export interface SetKeychainEntryRequestV1 { /** - * The key for the entry to set on the keychain. + * The key for the entry to check on the keychain. * @type {string} - * @memberof SetKeychainEntryRequest + * @memberof SetKeychainEntryRequestV1 */ key: string; /** * The value that will be associated with the key on the keychain. * @type {string} - * @memberof SetKeychainEntryRequest + * @memberof SetKeychainEntryRequestV1 */ value: string; } /** * * @export - * @interface SetKeychainEntryResponse + * @interface SetKeychainEntryResponseV1 */ -export interface SetKeychainEntryResponse { +export interface SetKeychainEntryResponseV1 { /** * The key that was used to set the value on the keychain. * @type {string} - * @memberof SetKeychainEntryResponse + * @memberof SetKeychainEntryResponseV1 */ key: string; } @@ -193,13 +193,13 @@ export const DefaultApiAxiosParamCreator = function (configuration?: Configurati /** * * @summary Retrieves the contents of a keychain entry from the backend. - * @param {GetKeychainEntryRequest} getKeychainEntryRequest Requst body to obtain a keychain entry via its key + * @param {GetKeychainEntryRequestV1} getKeychainEntryRequestV1 Request body to obtain a keychain entry via its key * @param {*} [options] Override http request option. * @throws {RequiredError} */ - getKeychainEntryV1: async (getKeychainEntryRequest: GetKeychainEntryRequest, options: any = {}): Promise => { - // verify required parameter 'getKeychainEntryRequest' is not null or undefined - assertParamExists('getKeychainEntryV1', 'getKeychainEntryRequest', getKeychainEntryRequest) + getKeychainEntryV1: async (getKeychainEntryRequestV1: GetKeychainEntryRequestV1, options: any = {}): Promise => { + // verify required parameter 'getKeychainEntryRequestV1' is not null or undefined + assertParamExists('getKeychainEntryV1', 'getKeychainEntryRequestV1', getKeychainEntryRequestV1) const localVarPath = `/api/v1/plugins/@hyperledger/cactus-plugin-keychain-vault/get-keychain-entry`; // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); @@ -219,7 +219,7 @@ export const DefaultApiAxiosParamCreator = function (configuration?: Configurati setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; - localVarRequestOptions.data = serializeDataIfNeeded(getKeychainEntryRequest, localVarRequestOptions, configuration) + localVarRequestOptions.data = serializeDataIfNeeded(getKeychainEntryRequestV1, localVarRequestOptions, configuration) return { url: toPathString(localVarUrlObj), @@ -293,13 +293,13 @@ export const DefaultApiAxiosParamCreator = function (configuration?: Configurati /** * * @summary Sets a value under a key on the keychain backend. - * @param {SetKeychainEntryRequest} setKeychainEntryRequest Requst body to write/update a keychain entry via its key + * @param {SetKeychainEntryRequestV1} setKeychainEntryRequestV1 Request body to write/update a keychain entry via its key * @param {*} [options] Override http request option. * @throws {RequiredError} */ - setKeychainEntryV1: async (setKeychainEntryRequest: SetKeychainEntryRequest, options: any = {}): Promise => { - // verify required parameter 'setKeychainEntryRequest' is not null or undefined - assertParamExists('setKeychainEntryV1', 'setKeychainEntryRequest', setKeychainEntryRequest) + setKeychainEntryV1: async (setKeychainEntryRequestV1: SetKeychainEntryRequestV1, options: any = {}): Promise => { + // verify required parameter 'setKeychainEntryRequestV1' is not null or undefined + assertParamExists('setKeychainEntryV1', 'setKeychainEntryRequestV1', setKeychainEntryRequestV1) const localVarPath = `/api/v1/plugins/@hyperledger/cactus-plugin-keychain-vault/set-keychain-entry`; // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); @@ -319,7 +319,7 @@ export const DefaultApiAxiosParamCreator = function (configuration?: Configurati setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; - localVarRequestOptions.data = serializeDataIfNeeded(setKeychainEntryRequest, localVarRequestOptions, configuration) + localVarRequestOptions.data = serializeDataIfNeeded(setKeychainEntryRequestV1, localVarRequestOptions, configuration) return { url: toPathString(localVarUrlObj), @@ -350,12 +350,12 @@ export const DefaultApiFp = function(configuration?: Configuration) { /** * * @summary Retrieves the contents of a keychain entry from the backend. - * @param {GetKeychainEntryRequest} getKeychainEntryRequest Requst body to obtain a keychain entry via its key + * @param {GetKeychainEntryRequestV1} getKeychainEntryRequestV1 Request body to obtain a keychain entry via its key * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async getKeychainEntryV1(getKeychainEntryRequest: GetKeychainEntryRequest, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.getKeychainEntryV1(getKeychainEntryRequest, options); + async getKeychainEntryV1(getKeychainEntryRequestV1: GetKeychainEntryRequestV1, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.getKeychainEntryV1(getKeychainEntryRequestV1, options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, /** @@ -382,12 +382,12 @@ export const DefaultApiFp = function(configuration?: Configuration) { /** * * @summary Sets a value under a key on the keychain backend. - * @param {SetKeychainEntryRequest} setKeychainEntryRequest Requst body to write/update a keychain entry via its key + * @param {SetKeychainEntryRequestV1} setKeychainEntryRequestV1 Request body to write/update a keychain entry via its key * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async setKeychainEntryV1(setKeychainEntryRequest: SetKeychainEntryRequest, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.setKeychainEntryV1(setKeychainEntryRequest, options); + async setKeychainEntryV1(setKeychainEntryRequestV1: SetKeychainEntryRequestV1, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.setKeychainEntryV1(setKeychainEntryRequestV1, options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, } @@ -413,12 +413,12 @@ export const DefaultApiFactory = function (configuration?: Configuration, basePa /** * * @summary Retrieves the contents of a keychain entry from the backend. - * @param {GetKeychainEntryRequest} getKeychainEntryRequest Requst body to obtain a keychain entry via its key + * @param {GetKeychainEntryRequestV1} getKeychainEntryRequestV1 Request body to obtain a keychain entry via its key * @param {*} [options] Override http request option. * @throws {RequiredError} */ - getKeychainEntryV1(getKeychainEntryRequest: GetKeychainEntryRequest, options?: any): AxiosPromise { - return localVarFp.getKeychainEntryV1(getKeychainEntryRequest, options).then((request) => request(axios, basePath)); + getKeychainEntryV1(getKeychainEntryRequestV1: GetKeychainEntryRequestV1, options?: any): AxiosPromise { + return localVarFp.getKeychainEntryV1(getKeychainEntryRequestV1, options).then((request) => request(axios, basePath)); }, /** * @@ -442,12 +442,12 @@ export const DefaultApiFactory = function (configuration?: Configuration, basePa /** * * @summary Sets a value under a key on the keychain backend. - * @param {SetKeychainEntryRequest} setKeychainEntryRequest Requst body to write/update a keychain entry via its key + * @param {SetKeychainEntryRequestV1} setKeychainEntryRequestV1 Request body to write/update a keychain entry via its key * @param {*} [options] Override http request option. * @throws {RequiredError} */ - setKeychainEntryV1(setKeychainEntryRequest: SetKeychainEntryRequest, options?: any): AxiosPromise { - return localVarFp.setKeychainEntryV1(setKeychainEntryRequest, options).then((request) => request(axios, basePath)); + setKeychainEntryV1(setKeychainEntryRequestV1: SetKeychainEntryRequestV1, options?: any): AxiosPromise { + return localVarFp.setKeychainEntryV1(setKeychainEntryRequestV1, options).then((request) => request(axios, basePath)); }, }; }; @@ -474,13 +474,13 @@ export class DefaultApi extends BaseAPI { /** * * @summary Retrieves the contents of a keychain entry from the backend. - * @param {GetKeychainEntryRequest} getKeychainEntryRequest Requst body to obtain a keychain entry via its key + * @param {GetKeychainEntryRequestV1} getKeychainEntryRequestV1 Request body to obtain a keychain entry via its key * @param {*} [options] Override http request option. * @throws {RequiredError} * @memberof DefaultApi */ - public getKeychainEntryV1(getKeychainEntryRequest: GetKeychainEntryRequest, options?: any) { - return DefaultApiFp(this.configuration).getKeychainEntryV1(getKeychainEntryRequest, options).then((request) => request(this.axios, this.basePath)); + public getKeychainEntryV1(getKeychainEntryRequestV1: GetKeychainEntryRequestV1, options?: any) { + return DefaultApiFp(this.configuration).getKeychainEntryV1(getKeychainEntryRequestV1, options).then((request) => request(this.axios, this.basePath)); } /** @@ -509,13 +509,13 @@ export class DefaultApi extends BaseAPI { /** * * @summary Sets a value under a key on the keychain backend. - * @param {SetKeychainEntryRequest} setKeychainEntryRequest Requst body to write/update a keychain entry via its key + * @param {SetKeychainEntryRequestV1} setKeychainEntryRequestV1 Request body to write/update a keychain entry via its key * @param {*} [options] Override http request option. * @throws {RequiredError} * @memberof DefaultApi */ - public setKeychainEntryV1(setKeychainEntryRequest: SetKeychainEntryRequest, options?: any) { - return DefaultApiFp(this.configuration).setKeychainEntryV1(setKeychainEntryRequest, options).then((request) => request(this.axios, this.basePath)); + public setKeychainEntryV1(setKeychainEntryRequestV1: SetKeychainEntryRequestV1, options?: any) { + return DefaultApiFp(this.configuration).setKeychainEntryV1(setKeychainEntryRequestV1, options).then((request) => request(this.axios, this.basePath)); } } diff --git a/packages/cactus-plugin-keychain-vault/src/main/typescript/web-services/get-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-vault/src/main/typescript/web-services/get-keychain-entry-endpoint-v1.ts index 1d2f22d67ff..33f6082d5ab 100644 --- a/packages/cactus-plugin-keychain-vault/src/main/typescript/web-services/get-keychain-entry-endpoint-v1.ts +++ b/packages/cactus-plugin-keychain-vault/src/main/typescript/web-services/get-keychain-entry-endpoint-v1.ts @@ -16,7 +16,7 @@ import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; import { PluginKeychainVault } from "../plugin-keychain-vault"; -import { GetKeychainEntryResponse } from "../generated/openapi/typescript-axios"; +import { GetKeychainEntryResponseV1 } from "../generated/openapi/typescript-axios"; export interface IGetKeychainEntryEndpointV1Options { logLevel?: LogLevelDesc; @@ -94,7 +94,7 @@ export class GetKeychainEntryEndpointV1 implements IWebServiceEndpoint { try { this.log.debug(`${tag} %o`, req.body); const value = await this.plugin.get(req.body.key); - const resBody: GetKeychainEntryResponse = { + const resBody: GetKeychainEntryResponseV1 = { key: req.body.key, value: value as string, }; 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 8255b4e650a..c6574de6887 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, };