Skip to content

Commit

Permalink
feat(keychain-aws-sm): complete request handler and endpoint
Browse files Browse the repository at this point in the history
Fixes hyperledger-cacti#967

Signed-off-by: Youngone Lee <youngone.lee@accenture.com>
  • Loading branch information
Leeyoungone committed Jul 21, 2021
1 parent ee4768e commit ba811ef
Show file tree
Hide file tree
Showing 10 changed files with 377 additions and 219 deletions.
64 changes: 62 additions & 2 deletions packages/cactus-core-api/src/main/json/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@
"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
Expand Down Expand Up @@ -512,7 +512,22 @@
}
}
},
"DeleteKeychainEntryResponse": {
"HasKeychainEntryRequest": {
"type": "object",
"required": [
"key"
],
"properties": {
"key": {
"type": "string",
"description": "The key for the entry to set on the keychain.",
"minLength": 1,
"maxLength": 1024,
"nullable": false
}
}
},
"HasKeychainEntryResponse": {
"type": "object",
"required": [
"key"
Expand All @@ -526,6 +541,21 @@
"nullable": false
}
}
},
"DeleteKeychainEntryResponse": {
"type": "object",
"required": [
"key"
],
"properties": {
"key": {
"type": "string",
"description": "The key that was used to delete the value on the keychain.",
"minLength": 1,
"maxLength": 1024,
"nullable": false
}
}
}
},
"requestBodies": {
Expand Down Expand Up @@ -561,6 +591,17 @@
}
}
}
},
"keychain_has_entry_request_body": {
"description": "Request body for a keychain entry via its key",
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HasKeychainEntryRequest"
}
}
}
}
},
"responses": {
Expand Down Expand Up @@ -623,6 +664,25 @@
},
"keychain_delete_entry_500": {
"description": "Unexpected error."
},
"keychain_has_entry_200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HasKeychainEntryResponse"
}
}
}
},
"keychain_has_entry_400": {
"description": "Bad request. Key must be a string and longer than 0, shorter than 1024 characters."
},
"keychain_has_entry_401": {
"description": "Authorization information is missing or invalid."
},
"keychain_has_entry_500": {
"description": "Unexpected error."
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,32 @@ export interface GetKeychainEntryResponse {
*/
value: string;
}
/**
*
* @export
* @interface HasKeychainEntryRequest
*/
export interface HasKeychainEntryRequest {
/**
* The key for the entry to set on the keychain.
* @type {string}
* @memberof HasKeychainEntryRequest
*/
key: string;
}
/**
*
* @export
* @interface HasKeychainEntryResponse
*/
export interface HasKeychainEntryResponse {
/**
* The key that was used to set the value on the keychain.
* @type {string}
* @memberof HasKeychainEntryResponse
*/
key: string;
}
/**
*
* @export
Expand Down
34 changes: 32 additions & 2 deletions packages/cactus-plugin-keychain-aws-sm/src/main/json/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
}
},
"operationId": "deleteKeychainEntry",
"summary": "Deletes a value under a key on the keychain backend.",
"summary": "Deletes an entry under a key on the keychain backend.",
"parameters": [],
"requestBody": {
"$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/requestBodies/keychain_delete_entry_request_body"
Expand All @@ -114,6 +114,36 @@
}
}
}
},
"/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": "hasKeychainEntry",
"summary": "Checks that an entry exists under a key on the keychain backend",
"parameters": [],
"requestBody": {
"$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/requestBodies/keychain_has_entry_request_body"
},
"responses": {
"200": {
"$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_has_entry_200"
},
"400": {
"$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_has_entry_400"
},
"401": {
"$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_has_entry_401"
},
"500": {
"$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_has_entry_500"
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,32 @@ export interface GetKeychainEntryResponse {
*/
value: string;
}
/**
*
* @export
* @interface HasKeychainEntryRequest
*/
export interface HasKeychainEntryRequest {
/**
* The key for the entry to set on the keychain.
* @type {string}
* @memberof HasKeychainEntryRequest
*/
key: string;
}
/**
*
* @export
* @interface HasKeychainEntryResponse
*/
export interface HasKeychainEntryResponse {
/**
* The key that was used to set the value on the keychain.
* @type {string}
* @memberof HasKeychainEntryResponse
*/
key: string;
}
/**
*
* @export
Expand Down Expand Up @@ -120,7 +146,7 @@ export const DefaultApiAxiosParamCreator = function (configuration?: Configurati
return {
/**
*
* @summary Deletes a value under a key on the keychain backend.
* @summary Deletes an entry under a key on the keychain backend.
* @param {DeleteKeychainEntryRequest} deleteKeychainEntryRequest Request body to delete a keychain entry via its key
* @param {*} [options] Override http request option.
* @throws {RequiredError}
Expand Down Expand Up @@ -190,6 +216,42 @@ export const DefaultApiAxiosParamCreator = function (configuration?: Configurati
options: localVarRequestOptions,
};
},
/**
*
* @summary Checks that an entry exists under a key on the keychain backend
* @param {HasKeychainEntryRequest} hasKeychainEntryRequest Request body for a keychain entry via its key
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
hasKeychainEntry: async (hasKeychainEntryRequest: HasKeychainEntryRequest, options: any = {}): Promise<RequestArgs> => {
// verify required parameter 'hasKeychainEntryRequest' is not null or undefined
assertParamExists('hasKeychainEntry', 'hasKeychainEntryRequest', hasKeychainEntryRequest)
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(hasKeychainEntryRequest, localVarRequestOptions, configuration)

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
*
* @summary Sets a value under a key on the keychain backend.
Expand Down Expand Up @@ -238,7 +300,7 @@ export const DefaultApiFp = function(configuration?: Configuration) {
return {
/**
*
* @summary Deletes a value under a key on the keychain backend.
* @summary Deletes an entry under a key on the keychain backend.
* @param {DeleteKeychainEntryRequest} deleteKeychainEntryRequest Request body to delete a keychain entry via its key
* @param {*} [options] Override http request option.
* @throws {RequiredError}
Expand All @@ -258,6 +320,17 @@ export const DefaultApiFp = function(configuration?: Configuration) {
const localVarAxiosArgs = await localVarAxiosParamCreator.getKeychainEntry(getKeychainEntryRequest, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
*
* @summary Checks that an entry exists under a key on the keychain backend
* @param {HasKeychainEntryRequest} hasKeychainEntryRequest Request body for a keychain entry via its key
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async hasKeychainEntry(hasKeychainEntryRequest: HasKeychainEntryRequest, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<HasKeychainEntryResponse>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.hasKeychainEntry(hasKeychainEntryRequest, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
*
* @summary Sets a value under a key on the keychain backend.
Expand All @@ -281,7 +354,7 @@ export const DefaultApiFactory = function (configuration?: Configuration, basePa
return {
/**
*
* @summary Deletes a value under a key on the keychain backend.
* @summary Deletes an entry under a key on the keychain backend.
* @param {DeleteKeychainEntryRequest} deleteKeychainEntryRequest Request body to delete a keychain entry via its key
* @param {*} [options] Override http request option.
* @throws {RequiredError}
Expand All @@ -299,6 +372,16 @@ export const DefaultApiFactory = function (configuration?: Configuration, basePa
getKeychainEntry(getKeychainEntryRequest: GetKeychainEntryRequest, options?: any): AxiosPromise<GetKeychainEntryResponse> {
return localVarFp.getKeychainEntry(getKeychainEntryRequest, options).then((request) => request(axios, basePath));
},
/**
*
* @summary Checks that an entry exists under a key on the keychain backend
* @param {HasKeychainEntryRequest} hasKeychainEntryRequest Request body for a keychain entry via its key
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
hasKeychainEntry(hasKeychainEntryRequest: HasKeychainEntryRequest, options?: any): AxiosPromise<HasKeychainEntryResponse> {
return localVarFp.hasKeychainEntry(hasKeychainEntryRequest, options).then((request) => request(axios, basePath));
},
/**
*
* @summary Sets a value under a key on the keychain backend.
Expand All @@ -321,7 +404,7 @@ export const DefaultApiFactory = function (configuration?: Configuration, basePa
export class DefaultApi extends BaseAPI {
/**
*
* @summary Deletes a value under a key on the keychain backend.
* @summary Deletes an entry under a key on the keychain backend.
* @param {DeleteKeychainEntryRequest} deleteKeychainEntryRequest Request body to delete a keychain entry via its key
* @param {*} [options] Override http request option.
* @throws {RequiredError}
Expand All @@ -343,6 +426,18 @@ export class DefaultApi extends BaseAPI {
return DefaultApiFp(this.configuration).getKeychainEntry(getKeychainEntryRequest, options).then((request) => request(this.axios, this.basePath));
}

/**
*
* @summary Checks that an entry exists under a key on the keychain backend
* @param {HasKeychainEntryRequest} hasKeychainEntryRequest Request body for a keychain entry via its key
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof DefaultApi
*/
public hasKeychainEntry(hasKeychainEntryRequest: HasKeychainEntryRequest, options?: any) {
return DefaultApiFp(this.configuration).hasKeychainEntry(hasKeychainEntryRequest, options).then((request) => request(this.axios, this.basePath));
}

/**
*
* @summary Sets a value under a key on the keychain backend.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import {
import { homedir } from "os";
import { PluginRegistry } from "../../../../cactus-core/dist/types/main/typescript/plugin-registry";
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",
Expand Down Expand Up @@ -164,6 +167,18 @@ export class PluginKeychainAwsSm
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ export interface IDeleteKeychainEntryEndpointOptions {
connector: PluginKeychainAwsSm;
}

export class DeleteKeychainEntryEndpoint implements IWebServiceEndpoint {
public static readonly CLASS_NAME = "DeleteKeychainEntryEndpoint";
export class DeleteKeychainEntryV1Endpoint implements IWebServiceEndpoint {
public static readonly CLASS_NAME = "DeleteKeychainEntryV1Endpoint";

private readonly log: Logger;

public get className(): string {
return DeleteKeychainEntryEndpoint.CLASS_NAME;
return DeleteKeychainEntryV1Endpoint.CLASS_NAME;
}

constructor(public readonly options: IDeleteKeychainEntryEndpointOptions) {
Expand Down
Loading

0 comments on commit ba811ef

Please sign in to comment.