From 48f2209307c02d7678082cb0791ea280d0059b08 Mon Sep 17 00:00:00 2001 From: Peter Somogyvari Date: Wed, 15 Nov 2023 20:32:58 -0800 Subject: [PATCH] feat(plugin-keychain-memory): add REST API endpoint implementations **BREAKING CHANGE**: Some of the schema elements that were redundant got removed from the openapi.json spec of the memory plugin. The same schemas are now being pulled from the core-api package. In this sense there is no breaking change because these two schemas were already equivalent anyway, but the fact is the openapi.json had schema elements removed from it anyway so this is something that people need to be aware of as they upgrade to v2.0.0 in the near future. 1. Added the REST API endpoints to the plugin so that it is accessible over HTTP for testing/demo purposes as necessary. 2. Also refactored the openapi.json spec file so that it pulls the schema definitions from the core-api package the same way as the keychain-memory-wasm plugin is doing already. 3. Migrated the test API client test case to Jest from tape 4. Refactored the `handleRequest` methods of the endpoint classes so that they perform the error handling with respect to the HTTP status codes being set correctly (sanitization is pending because I have to send a separate PR for that to the cactus-core package) Special thanks to @outSH for the suggestions to improve things! Signed-off-by: Peter Somogyvari --- .../src/main/json/openapi.json | 238 ++++++----- .../kotlin-client/.openapi-generator/FILES | 12 +- .../generated/openapi/kotlin-client/README.md | 18 +- .../openapitools/client/apis/DefaultApi.kt | 296 ++++++++++++++ .../models/DeleteKeychainEntryRequestV1.kt | 36 ++ .../models/DeleteKeychainEntryResponseV1.kt | 36 ++ .../models/GetKeychainEntryRequestV1.kt | 36 ++ .../models/GetKeychainEntryResponseV1.kt | 41 ++ .../models/HasKeychainEntryRequestV1.kt | 36 ++ .../models/HasKeychainEntryResponseV1.kt | 46 +++ .../models/SetKeychainEntryRequestV1.kt | 41 ++ .../models/SetKeychainEntryResponseV1.kt | 36 ++ .../generated/openapi/typescript-axios/api.ts | 370 +++++++++++++++++- .../openapi/typescript-axios/base.ts | 2 +- .../openapi/typescript-axios/common.ts | 2 +- .../openapi/typescript-axios/configuration.ts | 2 +- .../openapi/typescript-axios/index.ts | 2 +- .../src/main/typescript/index.ts | 20 + .../main/typescript/plugin-keychain-memory.ts | 63 ++- .../delete-keychain-entry-endpoint-v1.ts | 102 +++++ .../get-keychain-entry-endpoint-v1.ts | 102 +++++ .../has-keychain-entry-endpoint-v1.ts | 109 ++++++ .../set-keychain-entry-endpoint-v1.ts | 102 +++++ .../plugin-keychain-memory-api-client.test.ts | 143 +++++++ .../unit/plugin-keychain-memory.test.ts | 5 +- 25 files changed, 1725 insertions(+), 171 deletions(-) create mode 100644 packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/DeleteKeychainEntryRequestV1.kt create mode 100644 packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/DeleteKeychainEntryResponseV1.kt create mode 100644 packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/GetKeychainEntryRequestV1.kt create mode 100644 packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/GetKeychainEntryResponseV1.kt create mode 100644 packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/HasKeychainEntryRequestV1.kt create mode 100644 packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/HasKeychainEntryResponseV1.kt create mode 100644 packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/SetKeychainEntryRequestV1.kt create mode 100644 packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/SetKeychainEntryResponseV1.kt create mode 100644 packages/cactus-plugin-keychain-memory/src/main/typescript/web-services/delete-keychain-entry-endpoint-v1.ts create mode 100644 packages/cactus-plugin-keychain-memory/src/main/typescript/web-services/get-keychain-entry-endpoint-v1.ts create mode 100644 packages/cactus-plugin-keychain-memory/src/main/typescript/web-services/has-keychain-entry-endpoint-v1.ts create mode 100644 packages/cactus-plugin-keychain-memory/src/main/typescript/web-services/set-keychain-entry-endpoint-v1.ts create mode 100644 packages/cactus-plugin-keychain-memory/src/test/typescript/unit/plugin-keychain-memory-api-client.test.ts diff --git a/packages/cactus-plugin-keychain-memory/src/main/json/openapi.json b/packages/cactus-plugin-keychain-memory/src/main/json/openapi.json index f8b0154d93..3641dbb691 100644 --- a/packages/cactus-plugin-keychain-memory/src/main/json/openapi.json +++ b/packages/cactus-plugin-keychain-memory/src/main/json/openapi.json @@ -2,7 +2,7 @@ "openapi": "3.0.3", "info": { "title": "Hyperledger Cactus Plugin - Keychain Memory ", - "description": "Contains/describes the Hyperledger Cactus Keychain Memory plugin.", + "description": "Contains/describes the Hyperledger Cacti Keychain Memory plugin.", "version": "v2.0.0-alpha.2", "license": { "name": "Apache-2.0", @@ -11,148 +11,136 @@ }, "components": { "schemas": { - "GetKeychainEntryRequest": { - "type": "object", - "required": ["key"], - "additionalProperties": false, - "properties": { - "key": { - "type": "string", - "description": "The key for the entry to get from the keychain.", - "minLength": 1, - "maxLength": 1024, - "nullable": false + "PrometheusExporterMetricsResponse": { + "type": "string", + "nullable": false + } + } + }, + "paths": { + "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/get-keychain-entry": { + "post": { + "x-hyperledger-cacti": { + "http": { + "path": "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/get-keychain-entry", + "verbLowerCase": "post" } - } - }, - "GetKeychainEntryResponse": { - "type": "object", - "required": ["key", "value"], - "properties": { - "key": { - "type": "string", - "description": "The key that was used to retrieve the value from the keychain.", - "minLength": 1, - "maxLength": 1024, - "nullable": false + }, + "operationId": "getKeychainEntryV1", + "summary": "Retrieves the contents of a keychain entry from the backend.", + "parameters": [], + "requestBody": { + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v2.0.0-alpha.2/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/v2.0.0-alpha.2/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_200" }, - "value": { - "type": "string", - "description": "The value associated with the requested key on the keychain.", - "minLength": 0, - "maxLength": 10485760, - "nullable": false - } - } - }, - "SetKeychainEntryRequest": { - "type": "object", - "required": ["key", "value"], - "additionalProperties": false, - "properties": { - "key": { - "type": "string", - "description": "The key for the entry to set on the keychain.", - "minLength": 1, - "maxLength": 1024, - "nullable": false + "400": { + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v2.0.0-alpha.2/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_400" }, - "value": { - "type": "string", - "description": "The value that will be associated with the key on the keychain.", - "minLength": 0, - "maxLength": 10485760, - "nullable": false + "401": { + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v2.0.0-alpha.2/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_401" + }, + "404": { + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v2.0.0-alpha.2/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_404" + }, + "500": { + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v2.0.0-alpha.2/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_get_entry_500" } } - }, - "SetKeychainEntryResponse": { - "type": "object", - "required": ["key"], - "properties": { - "key": { - "type": "string", - "description": "The key that was used to set the value on the keychain.", - "minLength": 1, - "maxLength": 1024, - "nullable": false + } + }, + "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/set-keychain-entry": { + "post": { + "x-hyperledger-cacti": { + "http": { + "path": "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/set-keychain-entry", + "verbLowerCase": "post" + } + }, + "operationId": "setKeychainEntryV1", + "summary": "Sets a value under a key on the keychain backend.", + "parameters": [], + "requestBody": { + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v2.0.0-alpha.2/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/v2.0.0-alpha.2/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_set_entry_200" + }, + "400": { + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v2.0.0-alpha.2/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_set_entry_400" + }, + "401": { + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v2.0.0-alpha.2/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_set_entry_401" + }, + "500": { + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v2.0.0-alpha.2/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_set_entry_500" } } - }, - "PrometheusExporterMetricsResponse": { - "type": "string", - "nullable": false } }, - "requestBodies": { - "keychain_get_entry_request_body": { - "description": "Request body to obtain a keychain entry via its key", - "required": true, - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/GetKeychainEntryRequest" - } + "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/delete-keychain-entry": { + "post": { + "x-hyperledger-cacti": { + "http": { + "path": "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/delete-keychain-entry", + "verbLowerCase": "post" } - } - }, - "keychain_set_entry_request_body": { - "description": "Request body to write/update a keychain entry via its key", - "required": true, - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/SetKeychainEntryRequest" - } + }, + "operationId": "deleteKeychainEntryV1", + "summary": "Deletes an entry under a key on the keychain backend.", + "parameters": [], + "requestBody": { + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v2.0.0-alpha.2/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/v2.0.0-alpha.2/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_delete_entry_200" + }, + "400": { + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v2.0.0-alpha.2/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_delete_entry_400" + }, + "401": { + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v2.0.0-alpha.2/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_delete_entry_401" + }, + "500": { + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v2.0.0-alpha.2/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_delete_entry_500" } } } }, - "responses": { - "keychain_get_entry_200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/GetKeychainEntryResponse" - } + "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/has-keychain-entry": { + "post": { + "x-hyperledger-cacti": { + "http": { + "path": "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/has-keychain-entry", + "verbLowerCase": "post" } - } - }, - "keychain_get_entry_400": { - "description": "Bad request. Key must be a string and longer than 0, shorter than 1024 characters." - }, - "keychain_get_entry_401": { - "description": "Authorization information is missing or invalid." - }, - "keychain_get_entry_404": { - "description": "A keychain item with the specified key was not found." - }, - "keychain_get_entry_500": { - "description": "Unexpected error." - }, - "keychain_set_entry_200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/SetKeychainEntryResponse" - } + }, + "operationId": "hasKeychainEntryV1", + "summary": "Checks that an entry exists under a key on the keychain backend", + "parameters": [], + "requestBody": { + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v2.0.0-alpha.2/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/v2.0.0-alpha.2/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_has_entry_200" + }, + "400": { + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v2.0.0-alpha.2/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_has_entry_400" + }, + "401": { + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v2.0.0-alpha.2/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_has_entry_401" + }, + "500": { + "$ref": "https://raw.githubusercontent.com/hyperledger/cactus/v2.0.0-alpha.2/packages/cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_has_entry_500" } } - }, - "keychain_set_entry_400": { - "description": "Bad request. Key must be a string and longer than 0, shorter than 1024 characters." - }, - "keychain_set_entry_401": { - "description": "Authorization information is missing or invalid." - }, - "keychain_set_entry_500": { - "description": "Unexpected error." } - } - }, - "paths": { + }, "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/get-prometheus-exporter-metrics": { "get": { "x-hyperledger-cacti": { diff --git a/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/.openapi-generator/FILES b/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/.openapi-generator/FILES index f95b7cb080..15e43f61f3 100644 --- a/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/.openapi-generator/FILES +++ b/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/.openapi-generator/FILES @@ -21,7 +21,11 @@ src/main/kotlin/org/openapitools/client/infrastructure/ResponseExtensions.kt src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt src/main/kotlin/org/openapitools/client/infrastructure/URIAdapter.kt src/main/kotlin/org/openapitools/client/infrastructure/UUIDAdapter.kt -src/main/kotlin/org/openapitools/client/models/GetKeychainEntryRequest.kt -src/main/kotlin/org/openapitools/client/models/GetKeychainEntryResponse.kt -src/main/kotlin/org/openapitools/client/models/SetKeychainEntryRequest.kt -src/main/kotlin/org/openapitools/client/models/SetKeychainEntryResponse.kt +src/main/kotlin/org/openapitools/client/models/DeleteKeychainEntryRequestV1.kt +src/main/kotlin/org/openapitools/client/models/DeleteKeychainEntryResponseV1.kt +src/main/kotlin/org/openapitools/client/models/GetKeychainEntryRequestV1.kt +src/main/kotlin/org/openapitools/client/models/GetKeychainEntryResponseV1.kt +src/main/kotlin/org/openapitools/client/models/HasKeychainEntryRequestV1.kt +src/main/kotlin/org/openapitools/client/models/HasKeychainEntryResponseV1.kt +src/main/kotlin/org/openapitools/client/models/SetKeychainEntryRequestV1.kt +src/main/kotlin/org/openapitools/client/models/SetKeychainEntryResponseV1.kt diff --git a/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/README.md b/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/README.md index 56e443b595..1db354ac3e 100644 --- a/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/README.md +++ b/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/README.md @@ -1,6 +1,6 @@ # org.openapitools.client - Kotlin client library for Hyperledger Cactus Plugin - Keychain Memory -Contains/describes the Hyperledger Cactus Keychain Memory plugin. +Contains/describes the Hyperledger Cacti Keychain Memory plugin. ## Overview This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate an API client. @@ -44,16 +44,24 @@ All URIs are relative to *http://localhost* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- +*DefaultApi* | [**deleteKeychainEntryV1**](docs/DefaultApi.md#deletekeychainentryv1) | **POST** /api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/delete-keychain-entry | Deletes an entry under a key on the keychain backend. +*DefaultApi* | [**getKeychainEntryV1**](docs/DefaultApi.md#getkeychainentryv1) | **POST** /api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/get-keychain-entry | Retrieves the contents of a keychain entry from the backend. *DefaultApi* | [**getPrometheusMetricsV1**](docs/DefaultApi.md#getprometheusmetricsv1) | **GET** /api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/get-prometheus-exporter-metrics | Get the Prometheus Metrics +*DefaultApi* | [**hasKeychainEntryV1**](docs/DefaultApi.md#haskeychainentryv1) | **POST** /api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/has-keychain-entry | Checks that an entry exists under a key on the keychain backend +*DefaultApi* | [**setKeychainEntryV1**](docs/DefaultApi.md#setkeychainentryv1) | **POST** /api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/set-keychain-entry | Sets a value under a key on the keychain backend. ## Documentation for Models - - [org.openapitools.client.models.GetKeychainEntryRequest](docs/GetKeychainEntryRequest.md) - - [org.openapitools.client.models.GetKeychainEntryResponse](docs/GetKeychainEntryResponse.md) - - [org.openapitools.client.models.SetKeychainEntryRequest](docs/SetKeychainEntryRequest.md) - - [org.openapitools.client.models.SetKeychainEntryResponse](docs/SetKeychainEntryResponse.md) + - [org.openapitools.client.models.DeleteKeychainEntryRequestV1](docs/DeleteKeychainEntryRequestV1.md) + - [org.openapitools.client.models.DeleteKeychainEntryResponseV1](docs/DeleteKeychainEntryResponseV1.md) + - [org.openapitools.client.models.GetKeychainEntryRequestV1](docs/GetKeychainEntryRequestV1.md) + - [org.openapitools.client.models.GetKeychainEntryResponseV1](docs/GetKeychainEntryResponseV1.md) + - [org.openapitools.client.models.HasKeychainEntryRequestV1](docs/HasKeychainEntryRequestV1.md) + - [org.openapitools.client.models.HasKeychainEntryResponseV1](docs/HasKeychainEntryResponseV1.md) + - [org.openapitools.client.models.SetKeychainEntryRequestV1](docs/SetKeychainEntryRequestV1.md) + - [org.openapitools.client.models.SetKeychainEntryResponseV1](docs/SetKeychainEntryResponseV1.md) diff --git a/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt b/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt index 6059971c7c..9655b8dd95 100644 --- a/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt +++ b/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt @@ -19,6 +19,14 @@ import java.io.IOException import okhttp3.OkHttpClient import okhttp3.HttpUrl +import org.openapitools.client.models.DeleteKeychainEntryRequestV1 +import org.openapitools.client.models.DeleteKeychainEntryResponseV1 +import org.openapitools.client.models.GetKeychainEntryRequestV1 +import org.openapitools.client.models.GetKeychainEntryResponseV1 +import org.openapitools.client.models.HasKeychainEntryRequestV1 +import org.openapitools.client.models.HasKeychainEntryResponseV1 +import org.openapitools.client.models.SetKeychainEntryRequestV1 +import org.openapitools.client.models.SetKeychainEntryResponseV1 import com.squareup.moshi.Json @@ -44,6 +52,150 @@ class DefaultApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient } } + /** + * Deletes an entry under a key on the keychain backend. + * + * @param deleteKeychainEntryRequestV1 Request body to delete a keychain entry via its key + * @return DeleteKeychainEntryResponseV1 + * @throws IllegalStateException If the request is not correctly configured + * @throws IOException Rethrows the OkHttp execute method exception + * @throws UnsupportedOperationException If the API returns an informational or redirection response + * @throws ClientException If the API returns a client error response + * @throws ServerException If the API returns a server error response + */ + @Suppress("UNCHECKED_CAST") + @Throws(IllegalStateException::class, IOException::class, UnsupportedOperationException::class, ClientException::class, ServerException::class) + fun deleteKeychainEntryV1(deleteKeychainEntryRequestV1: DeleteKeychainEntryRequestV1) : DeleteKeychainEntryResponseV1 { + val localVarResponse = deleteKeychainEntryV1WithHttpInfo(deleteKeychainEntryRequestV1 = deleteKeychainEntryRequestV1) + + return when (localVarResponse.responseType) { + ResponseType.Success -> (localVarResponse as Success<*>).data as DeleteKeychainEntryResponseV1 + ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") + ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") + ResponseType.ClientError -> { + val localVarError = localVarResponse as ClientError<*> + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) + } + ResponseType.ServerError -> { + val localVarError = localVarResponse as ServerError<*> + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) + } + } + } + + /** + * Deletes an entry under a key on the keychain backend. + * + * @param deleteKeychainEntryRequestV1 Request body to delete a keychain entry via its key + * @return ApiResponse + * @throws IllegalStateException If the request is not correctly configured + * @throws IOException Rethrows the OkHttp execute method exception + */ + @Suppress("UNCHECKED_CAST") + @Throws(IllegalStateException::class, IOException::class) + fun deleteKeychainEntryV1WithHttpInfo(deleteKeychainEntryRequestV1: DeleteKeychainEntryRequestV1) : ApiResponse { + val localVariableConfig = deleteKeychainEntryV1RequestConfig(deleteKeychainEntryRequestV1 = deleteKeychainEntryRequestV1) + + return request( + localVariableConfig + ) + } + + /** + * To obtain the request config of the operation deleteKeychainEntryV1 + * + * @param deleteKeychainEntryRequestV1 Request body to delete a keychain entry via its key + * @return RequestConfig + */ + fun deleteKeychainEntryV1RequestConfig(deleteKeychainEntryRequestV1: DeleteKeychainEntryRequestV1) : RequestConfig { + val localVariableBody = deleteKeychainEntryRequestV1 + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + localVariableHeaders["Content-Type"] = "application/json" + localVariableHeaders["Accept"] = "application/json" + + return RequestConfig( + method = RequestMethod.POST, + path = "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/delete-keychain-entry", + query = localVariableQuery, + headers = localVariableHeaders, + requiresAuthentication = false, + body = localVariableBody + ) + } + + /** + * Retrieves the contents of a keychain entry from the backend. + * + * @param getKeychainEntryRequestV1 Request body to obtain a keychain entry via its key + * @return GetKeychainEntryResponseV1 + * @throws IllegalStateException If the request is not correctly configured + * @throws IOException Rethrows the OkHttp execute method exception + * @throws UnsupportedOperationException If the API returns an informational or redirection response + * @throws ClientException If the API returns a client error response + * @throws ServerException If the API returns a server error response + */ + @Suppress("UNCHECKED_CAST") + @Throws(IllegalStateException::class, IOException::class, UnsupportedOperationException::class, ClientException::class, ServerException::class) + fun getKeychainEntryV1(getKeychainEntryRequestV1: GetKeychainEntryRequestV1) : GetKeychainEntryResponseV1 { + val localVarResponse = getKeychainEntryV1WithHttpInfo(getKeychainEntryRequestV1 = getKeychainEntryRequestV1) + + return when (localVarResponse.responseType) { + ResponseType.Success -> (localVarResponse as Success<*>).data as GetKeychainEntryResponseV1 + ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") + ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") + ResponseType.ClientError -> { + val localVarError = localVarResponse as ClientError<*> + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) + } + ResponseType.ServerError -> { + val localVarError = localVarResponse as ServerError<*> + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) + } + } + } + + /** + * Retrieves the contents of a keychain entry from the backend. + * + * @param getKeychainEntryRequestV1 Request body to obtain a keychain entry via its key + * @return ApiResponse + * @throws IllegalStateException If the request is not correctly configured + * @throws IOException Rethrows the OkHttp execute method exception + */ + @Suppress("UNCHECKED_CAST") + @Throws(IllegalStateException::class, IOException::class) + fun getKeychainEntryV1WithHttpInfo(getKeychainEntryRequestV1: GetKeychainEntryRequestV1) : ApiResponse { + val localVariableConfig = getKeychainEntryV1RequestConfig(getKeychainEntryRequestV1 = getKeychainEntryRequestV1) + + return request( + localVariableConfig + ) + } + + /** + * To obtain the request config of the operation getKeychainEntryV1 + * + * @param getKeychainEntryRequestV1 Request body to obtain a keychain entry via its key + * @return RequestConfig + */ + fun getKeychainEntryV1RequestConfig(getKeychainEntryRequestV1: GetKeychainEntryRequestV1) : RequestConfig { + val localVariableBody = getKeychainEntryRequestV1 + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + localVariableHeaders["Content-Type"] = "application/json" + localVariableHeaders["Accept"] = "application/json" + + return RequestConfig( + method = RequestMethod.POST, + path = "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/get-keychain-entry", + query = localVariableQuery, + headers = localVariableHeaders, + requiresAuthentication = false, + body = localVariableBody + ) + } + /** * Get the Prometheus Metrics * @@ -111,6 +263,150 @@ class DefaultApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient ) } + /** + * Checks that an entry exists under a key on the keychain backend + * + * @param hasKeychainEntryRequestV1 Request body for checking a keychain entry via its key + * @return HasKeychainEntryResponseV1 + * @throws IllegalStateException If the request is not correctly configured + * @throws IOException Rethrows the OkHttp execute method exception + * @throws UnsupportedOperationException If the API returns an informational or redirection response + * @throws ClientException If the API returns a client error response + * @throws ServerException If the API returns a server error response + */ + @Suppress("UNCHECKED_CAST") + @Throws(IllegalStateException::class, IOException::class, UnsupportedOperationException::class, ClientException::class, ServerException::class) + fun hasKeychainEntryV1(hasKeychainEntryRequestV1: HasKeychainEntryRequestV1) : HasKeychainEntryResponseV1 { + val localVarResponse = hasKeychainEntryV1WithHttpInfo(hasKeychainEntryRequestV1 = hasKeychainEntryRequestV1) + + return when (localVarResponse.responseType) { + ResponseType.Success -> (localVarResponse as Success<*>).data as HasKeychainEntryResponseV1 + ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") + ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") + ResponseType.ClientError -> { + val localVarError = localVarResponse as ClientError<*> + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) + } + ResponseType.ServerError -> { + val localVarError = localVarResponse as ServerError<*> + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) + } + } + } + + /** + * Checks that an entry exists under a key on the keychain backend + * + * @param hasKeychainEntryRequestV1 Request body for checking a keychain entry via its key + * @return ApiResponse + * @throws IllegalStateException If the request is not correctly configured + * @throws IOException Rethrows the OkHttp execute method exception + */ + @Suppress("UNCHECKED_CAST") + @Throws(IllegalStateException::class, IOException::class) + fun hasKeychainEntryV1WithHttpInfo(hasKeychainEntryRequestV1: HasKeychainEntryRequestV1) : ApiResponse { + val localVariableConfig = hasKeychainEntryV1RequestConfig(hasKeychainEntryRequestV1 = hasKeychainEntryRequestV1) + + return request( + localVariableConfig + ) + } + + /** + * To obtain the request config of the operation hasKeychainEntryV1 + * + * @param hasKeychainEntryRequestV1 Request body for checking a keychain entry via its key + * @return RequestConfig + */ + fun hasKeychainEntryV1RequestConfig(hasKeychainEntryRequestV1: HasKeychainEntryRequestV1) : RequestConfig { + val localVariableBody = hasKeychainEntryRequestV1 + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + localVariableHeaders["Content-Type"] = "application/json" + localVariableHeaders["Accept"] = "application/json" + + return RequestConfig( + method = RequestMethod.POST, + path = "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/has-keychain-entry", + query = localVariableQuery, + headers = localVariableHeaders, + requiresAuthentication = false, + body = localVariableBody + ) + } + + /** + * Sets a value under a key on the keychain backend. + * + * @param setKeychainEntryRequestV1 Request body to write/update a keychain entry via its key + * @return SetKeychainEntryResponseV1 + * @throws IllegalStateException If the request is not correctly configured + * @throws IOException Rethrows the OkHttp execute method exception + * @throws UnsupportedOperationException If the API returns an informational or redirection response + * @throws ClientException If the API returns a client error response + * @throws ServerException If the API returns a server error response + */ + @Suppress("UNCHECKED_CAST") + @Throws(IllegalStateException::class, IOException::class, UnsupportedOperationException::class, ClientException::class, ServerException::class) + fun setKeychainEntryV1(setKeychainEntryRequestV1: SetKeychainEntryRequestV1) : SetKeychainEntryResponseV1 { + val localVarResponse = setKeychainEntryV1WithHttpInfo(setKeychainEntryRequestV1 = setKeychainEntryRequestV1) + + return when (localVarResponse.responseType) { + ResponseType.Success -> (localVarResponse as Success<*>).data as SetKeychainEntryResponseV1 + ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") + ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") + ResponseType.ClientError -> { + val localVarError = localVarResponse as ClientError<*> + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) + } + ResponseType.ServerError -> { + val localVarError = localVarResponse as ServerError<*> + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) + } + } + } + + /** + * Sets a value under a key on the keychain backend. + * + * @param setKeychainEntryRequestV1 Request body to write/update a keychain entry via its key + * @return ApiResponse + * @throws IllegalStateException If the request is not correctly configured + * @throws IOException Rethrows the OkHttp execute method exception + */ + @Suppress("UNCHECKED_CAST") + @Throws(IllegalStateException::class, IOException::class) + fun setKeychainEntryV1WithHttpInfo(setKeychainEntryRequestV1: SetKeychainEntryRequestV1) : ApiResponse { + val localVariableConfig = setKeychainEntryV1RequestConfig(setKeychainEntryRequestV1 = setKeychainEntryRequestV1) + + return request( + localVariableConfig + ) + } + + /** + * To obtain the request config of the operation setKeychainEntryV1 + * + * @param setKeychainEntryRequestV1 Request body to write/update a keychain entry via its key + * @return RequestConfig + */ + fun setKeychainEntryV1RequestConfig(setKeychainEntryRequestV1: SetKeychainEntryRequestV1) : RequestConfig { + val localVariableBody = setKeychainEntryRequestV1 + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + localVariableHeaders["Content-Type"] = "application/json" + localVariableHeaders["Accept"] = "application/json" + + return RequestConfig( + method = RequestMethod.POST, + path = "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/set-keychain-entry", + query = localVariableQuery, + headers = localVariableHeaders, + requiresAuthentication = false, + body = localVariableBody + ) + } + private fun encodeURIComponent(uriComponent: kotlin.String): kotlin.String = HttpUrl.Builder().scheme("http").host("localhost").addPathSegment(uriComponent).build().encodedPathSegments[0] diff --git a/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/DeleteKeychainEntryRequestV1.kt b/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/DeleteKeychainEntryRequestV1.kt new file mode 100644 index 0000000000..58a98174cf --- /dev/null +++ b/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/DeleteKeychainEntryRequestV1.kt @@ -0,0 +1,36 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.models + + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +/** + * + * + * @param key The key for the entry to check the presence of on the keychain. + */ + + +data class DeleteKeychainEntryRequestV1 ( + + /* The key for the entry to check the presence of on the keychain. */ + @Json(name = "key") + val key: kotlin.String + +) + diff --git a/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/DeleteKeychainEntryResponseV1.kt b/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/DeleteKeychainEntryResponseV1.kt new file mode 100644 index 0000000000..7b8b874e3d --- /dev/null +++ b/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/DeleteKeychainEntryResponseV1.kt @@ -0,0 +1,36 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.models + + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +/** + * + * + * @param key The key that was deleted from the keychain. + */ + + +data class DeleteKeychainEntryResponseV1 ( + + /* The key that was deleted from the keychain. */ + @Json(name = "key") + val key: kotlin.String + +) + diff --git a/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/GetKeychainEntryRequestV1.kt b/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/GetKeychainEntryRequestV1.kt new file mode 100644 index 0000000000..ea1d0da587 --- /dev/null +++ b/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/GetKeychainEntryRequestV1.kt @@ -0,0 +1,36 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.models + + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +/** + * + * + * @param key The key for the entry to get from the keychain. + */ + + +data class GetKeychainEntryRequestV1 ( + + /* The key for the entry to get from the keychain. */ + @Json(name = "key") + val key: kotlin.String + +) + diff --git a/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/GetKeychainEntryResponseV1.kt b/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/GetKeychainEntryResponseV1.kt new file mode 100644 index 0000000000..21b9a38b46 --- /dev/null +++ b/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/GetKeychainEntryResponseV1.kt @@ -0,0 +1,41 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.models + + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +/** + * + * + * @param key The key that was used to retrieve the value from the keychain. + * @param `value` The value associated with the requested key on the keychain. + */ + + +data class GetKeychainEntryResponseV1 ( + + /* The key that was used to retrieve the value from the keychain. */ + @Json(name = "key") + val key: kotlin.String, + + /* The value associated with the requested key on the keychain. */ + @Json(name = "value") + val `value`: kotlin.String + +) + diff --git a/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/HasKeychainEntryRequestV1.kt b/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/HasKeychainEntryRequestV1.kt new file mode 100644 index 0000000000..c3055c3414 --- /dev/null +++ b/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/HasKeychainEntryRequestV1.kt @@ -0,0 +1,36 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.models + + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +/** + * + * + * @param key The key to check for presence in the keychain. + */ + + +data class HasKeychainEntryRequestV1 ( + + /* The key to check for presence in the keychain. */ + @Json(name = "key") + val key: kotlin.String + +) + diff --git a/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/HasKeychainEntryResponseV1.kt b/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/HasKeychainEntryResponseV1.kt new file mode 100644 index 0000000000..6345c51831 --- /dev/null +++ b/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/HasKeychainEntryResponseV1.kt @@ -0,0 +1,46 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.models + + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +/** + * + * + * @param key The key that was used to check the presence of the value in the entry store. + * @param checkedAt Date and time encoded as JSON when the presence check was performed by the plugin backend. + * @param isPresent The boolean true or false indicating the presence or absence of an entry under 'key'. + */ + + +data class HasKeychainEntryResponseV1 ( + + /* The key that was used to check the presence of the value in the entry store. */ + @Json(name = "key") + val key: kotlin.String, + + /* Date and time encoded as JSON when the presence check was performed by the plugin backend. */ + @Json(name = "checkedAt") + val checkedAt: kotlin.String, + + /* The boolean true or false indicating the presence or absence of an entry under 'key'. */ + @Json(name = "isPresent") + val isPresent: kotlin.Boolean + +) + diff --git a/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/SetKeychainEntryRequestV1.kt b/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/SetKeychainEntryRequestV1.kt new file mode 100644 index 0000000000..d016fc72e6 --- /dev/null +++ b/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/SetKeychainEntryRequestV1.kt @@ -0,0 +1,41 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.models + + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +/** + * + * + * @param key The key for the entry to set on the keychain. + * @param `value` The value that will be associated with the key on the keychain. + */ + + +data class SetKeychainEntryRequestV1 ( + + /* The key for the entry to set on the keychain. */ + @Json(name = "key") + val key: kotlin.String, + + /* The value that will be associated with the key on the keychain. */ + @Json(name = "value") + val `value`: kotlin.String + +) + diff --git a/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/SetKeychainEntryResponseV1.kt b/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/SetKeychainEntryResponseV1.kt new file mode 100644 index 0000000000..3f7624cd59 --- /dev/null +++ b/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/SetKeychainEntryResponseV1.kt @@ -0,0 +1,36 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.models + + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +/** + * + * + * @param key The key that was used to set the value on the keychain. + */ + + +data class SetKeychainEntryResponseV1 ( + + /* The key that was used to set the value on the keychain. */ + @Json(name = "key") + val key: kotlin.String + +) + diff --git a/packages/cactus-plugin-keychain-memory/src/main/typescript/generated/openapi/typescript-axios/api.ts b/packages/cactus-plugin-keychain-memory/src/main/typescript/generated/openapi/typescript-axios/api.ts index 57d38fed98..de3b3a3890 100644 --- a/packages/cactus-plugin-keychain-memory/src/main/typescript/generated/openapi/typescript-axios/api.ts +++ b/packages/cactus-plugin-keychain-memory/src/main/typescript/generated/openapi/typescript-axios/api.ts @@ -2,7 +2,7 @@ /* eslint-disable */ /** * Hyperledger Cactus Plugin - Keychain Memory - * Contains/describes the Hyperledger Cactus Keychain Memory plugin. + * Contains/describes the Hyperledger Cacti Keychain Memory plugin. * * The version of the OpenAPI document: v2.0.0-alpha.2 * @@ -26,64 +26,128 @@ import { BASE_PATH, COLLECTION_FORMATS, BaseAPI, RequiredError } from './base'; /** * * @export - * @interface GetKeychainEntryRequest + * @interface DeleteKeychainEntryRequestV1 */ -export interface GetKeychainEntryRequest { +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 + * @interface GetKeychainEntryRequestV1 + */ +export interface GetKeychainEntryRequestV1 { /** * The key for the entry to get 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; } /** * * @export - * @interface SetKeychainEntryRequest + * @interface HasKeychainEntryRequestV1 */ -export interface SetKeychainEntryRequest { +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 + * @interface SetKeychainEntryRequestV1 + */ +export interface SetKeychainEntryRequestV1 { /** * The key for the entry to set 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; } @@ -94,6 +158,78 @@ 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: AxiosRequestConfig = {}): Promise => { + // verify required parameter 'deleteKeychainEntryRequestV1' is not null or undefined + assertParamExists('deleteKeychainEntryV1', 'deleteKeychainEntryRequestV1', deleteKeychainEntryRequestV1) + const localVarPath = `/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/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); + 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. + * @param {GetKeychainEntryRequestV1} getKeychainEntryRequestV1 Request body to obtain a keychain entry via its key + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getKeychainEntryV1: async (getKeychainEntryRequestV1: GetKeychainEntryRequestV1, options: AxiosRequestConfig = {}): Promise => { + // verify required parameter 'getKeychainEntryRequestV1' is not null or undefined + assertParamExists('getKeychainEntryV1', 'getKeychainEntryRequestV1', getKeychainEntryRequestV1) + const localVarPath = `/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/get-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); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + localVarRequestOptions.data = serializeDataIfNeeded(getKeychainEntryRequestV1, localVarRequestOptions, configuration) + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, /** * * @summary Get the Prometheus Metrics @@ -119,6 +255,78 @@ export const DefaultApiAxiosParamCreator = function (configuration?: Configurati let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + return { + url: toPathString(localVarUrlObj), + 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: AxiosRequestConfig = {}): Promise => { + // verify required parameter 'hasKeychainEntryRequestV1' is not null or undefined + assertParamExists('hasKeychainEntryV1', 'hasKeychainEntryRequestV1', hasKeychainEntryRequestV1) + const localVarPath = `/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/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); + 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. + * @param {SetKeychainEntryRequestV1} setKeychainEntryRequestV1 Request body to write/update a keychain entry via its key + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + setKeychainEntryV1: async (setKeychainEntryRequestV1: SetKeychainEntryRequestV1, options: AxiosRequestConfig = {}): Promise => { + // verify required parameter 'setKeychainEntryRequestV1' is not null or undefined + assertParamExists('setKeychainEntryV1', 'setKeychainEntryRequestV1', setKeychainEntryRequestV1) + const localVarPath = `/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/set-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); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + localVarRequestOptions.data = serializeDataIfNeeded(setKeychainEntryRequestV1, localVarRequestOptions, configuration) + return { url: toPathString(localVarUrlObj), options: localVarRequestOptions, @@ -134,6 +342,28 @@ 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?: AxiosRequestConfig): 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. + * @param {GetKeychainEntryRequestV1} getKeychainEntryRequestV1 Request body to obtain a keychain entry via its key + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async getKeychainEntryV1(getKeychainEntryRequestV1: GetKeychainEntryRequestV1, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.getKeychainEntryV1(getKeychainEntryRequestV1, options); + return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); + }, /** * * @summary Get the Prometheus Metrics @@ -144,6 +374,28 @@ export const DefaultApiFp = function(configuration?: Configuration) { const localVarAxiosArgs = await localVarAxiosParamCreator.getPrometheusMetricsV1(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?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.hasKeychainEntryV1(hasKeychainEntryRequestV1, options); + return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); + }, + /** + * + * @summary Sets a value under a key on the keychain backend. + * @param {SetKeychainEntryRequestV1} setKeychainEntryRequestV1 Request body to write/update a keychain entry via its key + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async setKeychainEntryV1(setKeychainEntryRequestV1: SetKeychainEntryRequestV1, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.setKeychainEntryV1(setKeychainEntryRequestV1, options); + return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); + }, } }; @@ -154,6 +406,26 @@ 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. + * @param {GetKeychainEntryRequestV1} getKeychainEntryRequestV1 Request body to obtain a keychain entry via its key + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getKeychainEntryV1(getKeychainEntryRequestV1: GetKeychainEntryRequestV1, options?: any): AxiosPromise { + return localVarFp.getKeychainEntryV1(getKeychainEntryRequestV1, options).then((request) => request(axios, basePath)); + }, /** * * @summary Get the Prometheus Metrics @@ -163,6 +435,26 @@ export const DefaultApiFactory = function (configuration?: Configuration, basePa getPrometheusMetricsV1(options?: any): AxiosPromise { return localVarFp.getPrometheusMetricsV1(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)); + }, + /** + * + * @summary Sets a value under a key on the keychain backend. + * @param {SetKeychainEntryRequestV1} setKeychainEntryRequestV1 Request body to write/update a keychain entry via its key + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + setKeychainEntryV1(setKeychainEntryRequestV1: SetKeychainEntryRequestV1, options?: any): AxiosPromise { + return localVarFp.setKeychainEntryV1(setKeychainEntryRequestV1, options).then((request) => request(axios, basePath)); + }, }; }; @@ -173,6 +465,30 @@ 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?: AxiosRequestConfig) { + 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. + * @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(getKeychainEntryRequestV1: GetKeychainEntryRequestV1, options?: AxiosRequestConfig) { + return DefaultApiFp(this.configuration).getKeychainEntryV1(getKeychainEntryRequestV1, options).then((request) => request(this.axios, this.basePath)); + } + /** * * @summary Get the Prometheus Metrics @@ -183,6 +499,30 @@ export class DefaultApi extends BaseAPI { public getPrometheusMetricsV1(options?: AxiosRequestConfig) { return DefaultApiFp(this.configuration).getPrometheusMetricsV1(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?: AxiosRequestConfig) { + return DefaultApiFp(this.configuration).hasKeychainEntryV1(hasKeychainEntryRequestV1, options).then((request) => request(this.axios, this.basePath)); + } + + /** + * + * @summary Sets a value under a key on the keychain backend. + * @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(setKeychainEntryRequestV1: SetKeychainEntryRequestV1, options?: AxiosRequestConfig) { + return DefaultApiFp(this.configuration).setKeychainEntryV1(setKeychainEntryRequestV1, options).then((request) => request(this.axios, this.basePath)); + } } diff --git a/packages/cactus-plugin-keychain-memory/src/main/typescript/generated/openapi/typescript-axios/base.ts b/packages/cactus-plugin-keychain-memory/src/main/typescript/generated/openapi/typescript-axios/base.ts index 5f958bb83f..d8e1f4ea3e 100644 --- a/packages/cactus-plugin-keychain-memory/src/main/typescript/generated/openapi/typescript-axios/base.ts +++ b/packages/cactus-plugin-keychain-memory/src/main/typescript/generated/openapi/typescript-axios/base.ts @@ -2,7 +2,7 @@ /* eslint-disable */ /** * Hyperledger Cactus Plugin - Keychain Memory - * Contains/describes the Hyperledger Cactus Keychain Memory plugin. + * Contains/describes the Hyperledger Cacti Keychain Memory plugin. * * The version of the OpenAPI document: v2.0.0-alpha.2 * diff --git a/packages/cactus-plugin-keychain-memory/src/main/typescript/generated/openapi/typescript-axios/common.ts b/packages/cactus-plugin-keychain-memory/src/main/typescript/generated/openapi/typescript-axios/common.ts index 520b79fa04..847a5ded70 100644 --- a/packages/cactus-plugin-keychain-memory/src/main/typescript/generated/openapi/typescript-axios/common.ts +++ b/packages/cactus-plugin-keychain-memory/src/main/typescript/generated/openapi/typescript-axios/common.ts @@ -2,7 +2,7 @@ /* eslint-disable */ /** * Hyperledger Cactus Plugin - Keychain Memory - * Contains/describes the Hyperledger Cactus Keychain Memory plugin. + * Contains/describes the Hyperledger Cacti Keychain Memory plugin. * * The version of the OpenAPI document: v2.0.0-alpha.2 * diff --git a/packages/cactus-plugin-keychain-memory/src/main/typescript/generated/openapi/typescript-axios/configuration.ts b/packages/cactus-plugin-keychain-memory/src/main/typescript/generated/openapi/typescript-axios/configuration.ts index e13abaad14..fc91fdd661 100644 --- a/packages/cactus-plugin-keychain-memory/src/main/typescript/generated/openapi/typescript-axios/configuration.ts +++ b/packages/cactus-plugin-keychain-memory/src/main/typescript/generated/openapi/typescript-axios/configuration.ts @@ -2,7 +2,7 @@ /* eslint-disable */ /** * Hyperledger Cactus Plugin - Keychain Memory - * Contains/describes the Hyperledger Cactus Keychain Memory plugin. + * Contains/describes the Hyperledger Cacti Keychain Memory plugin. * * The version of the OpenAPI document: v2.0.0-alpha.2 * diff --git a/packages/cactus-plugin-keychain-memory/src/main/typescript/generated/openapi/typescript-axios/index.ts b/packages/cactus-plugin-keychain-memory/src/main/typescript/generated/openapi/typescript-axios/index.ts index 7249c9c74a..68edaef2c7 100644 --- a/packages/cactus-plugin-keychain-memory/src/main/typescript/generated/openapi/typescript-axios/index.ts +++ b/packages/cactus-plugin-keychain-memory/src/main/typescript/generated/openapi/typescript-axios/index.ts @@ -2,7 +2,7 @@ /* eslint-disable */ /** * Hyperledger Cactus Plugin - Keychain Memory - * Contains/describes the Hyperledger Cactus Keychain Memory plugin. + * Contains/describes the Hyperledger Cacti Keychain Memory plugin. * * The version of the OpenAPI document: v2.0.0-alpha.2 * diff --git a/packages/cactus-plugin-keychain-memory/src/main/typescript/index.ts b/packages/cactus-plugin-keychain-memory/src/main/typescript/index.ts index 87cb558397..358eab3683 100755 --- a/packages/cactus-plugin-keychain-memory/src/main/typescript/index.ts +++ b/packages/cactus-plugin-keychain-memory/src/main/typescript/index.ts @@ -1 +1,21 @@ export * from "./public-api"; + +export { + DeleteKeychainEntryV1Endpoint, + IDeleteKeychainEntryEndpointOptions, +} from "./web-services/delete-keychain-entry-endpoint-v1"; + +export { + GetKeychainEntryV1Endpoint, + IGetKeychainEntryEndpointOptions, +} from "./web-services/get-keychain-entry-endpoint-v1"; + +export { + HasKeychainEntryV1Endpoint, + IHasKeychainEntryEndpointOptions, +} from "./web-services/has-keychain-entry-endpoint-v1"; + +export { + ISetKeychainEntryEndpointOptions, + SetKeychainEntryV1Endpoint, +} from "./web-services/set-keychain-entry-endpoint-v1"; diff --git a/packages/cactus-plugin-keychain-memory/src/main/typescript/plugin-keychain-memory.ts b/packages/cactus-plugin-keychain-memory/src/main/typescript/plugin-keychain-memory.ts index 3b1555f7b5..93e8dbb827 100644 --- a/packages/cactus-plugin-keychain-memory/src/main/typescript/plugin-keychain-memory.ts +++ b/packages/cactus-plugin-keychain-memory/src/main/typescript/plugin-keychain-memory.ts @@ -6,6 +6,8 @@ import { } from "@hyperledger/cactus-common"; import { ICactusPluginOptions, + IPluginKeychain, + IPluginWebService, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; @@ -14,10 +16,11 @@ import OAS from "../json/openapi.json"; import { PrometheusExporter } from "./prometheus-exporter/prometheus-exporter"; import { Express } from "express"; -import { - IGetPrometheusExporterMetricsEndpointV1Options, - GetPrometheusExporterMetricsEndpointV1, -} from "./get-prometheus-exporter-metrics/get-prometheus-exporter-metrics-endpoint-v1"; +import { GetPrometheusExporterMetricsEndpointV1 } from "./get-prometheus-exporter-metrics/get-prometheus-exporter-metrics-endpoint-v1"; +import { SetKeychainEntryV1Endpoint } from "./web-services/set-keychain-entry-endpoint-v1"; +import { GetKeychainEntryV1Endpoint } from "./web-services/get-keychain-entry-endpoint-v1"; +import { DeleteKeychainEntryV1Endpoint } from "./web-services/delete-keychain-entry-endpoint-v1"; +import { HasKeychainEntryV1Endpoint } from "./web-services/has-keychain-entry-endpoint-v1"; export interface IPluginKeychainMemoryOptions extends ICactusPluginOptions { logLevel?: LogLevelDesc; @@ -26,12 +29,15 @@ export interface IPluginKeychainMemoryOptions extends ICactusPluginOptions { prometheusExporter?: PrometheusExporter; } -export class PluginKeychainMemory { +export class PluginKeychainMemory + implements IPluginKeychain, IPluginWebService +{ public static readonly CLASS_NAME = "PluginKeychainMemory"; private readonly backend: Map; private readonly log: Logger; private readonly instanceId: string; + private endpoints: IWebServiceEndpoint[] | undefined; public prometheusExporter: PrometheusExporter; public get className(): string { @@ -83,23 +89,44 @@ export class PluginKeychainMemory { return res; } - public async getOrCreateWebServices( - expressApp: Express, - ): Promise { + async registerWebServices(app: Express): Promise { + const webServices = await this.getOrCreateWebServices(); + await Promise.all(webServices.map((ws) => ws.registerExpress(app))); + return webServices; + } + + public async getOrCreateWebServices(): Promise { const { log } = this; log.info(`Installing web services for plugin ${this.getPackageName()}...`); - const endpoints: IWebServiceEndpoint[] = []; - { - const opts: IGetPrometheusExporterMetricsEndpointV1Options = { + if (Array.isArray(this.endpoints)) { + return this.endpoints; + } + const endpoints: IWebServiceEndpoint[] = [ + new SetKeychainEntryV1Endpoint({ plugin: this, logLevel: this.opts.logLevel, - }; - const endpoint = new GetPrometheusExporterMetricsEndpointV1(opts); - endpoint.registerExpress(expressApp); - endpoints.push(endpoint); - } + }), + new GetKeychainEntryV1Endpoint({ + plugin: this, + logLevel: this.opts.logLevel, + }), + new DeleteKeychainEntryV1Endpoint({ + plugin: this, + logLevel: this.opts.logLevel, + }), + new HasKeychainEntryV1Endpoint({ + plugin: this, + logLevel: this.opts.logLevel, + }), + new GetPrometheusExporterMetricsEndpointV1({ + plugin: this, + logLevel: this.opts.logLevel, + }), + ]; + + this.endpoints = endpoints; const pkg = this.getPackageName(); log.info(`Installed web services for plugin ${pkg} OK`, { endpoints }); @@ -107,6 +134,10 @@ export class PluginKeychainMemory { return endpoints; } + public async shutdown(): Promise { + return; + } + public getInstanceId(): string { return this.instanceId; } diff --git a/packages/cactus-plugin-keychain-memory/src/main/typescript/web-services/delete-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-memory/src/main/typescript/web-services/delete-keychain-entry-endpoint-v1.ts new file mode 100644 index 0000000000..f247b1b294 --- /dev/null +++ b/packages/cactus-plugin-keychain-memory/src/main/typescript/web-services/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 { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; +import { DeleteKeychainEntryRequestV1 } from "@hyperledger/cactus-core-api"; + +import OAS from "../../json/openapi.json"; +import { PluginKeychainMemory } from "../plugin-keychain-memory"; + +export interface IDeleteKeychainEntryEndpointOptions { + logLevel?: LogLevelDesc; + plugin: PluginKeychainMemory; +} + +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.plugin, `${fnTag} arg options.connector`); + + const level = this.options.logLevel || "INFO"; + const label = this.className; + this.log = LoggerProvider.getOrCreate({ level, label }); + } + + public getOasPath(): (typeof OAS.paths)["/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/delete-keychain-entry"] { + return OAS.paths[ + "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/delete-keychain-entry" + ]; + } + + public getPath(): string { + const apiPath = this.getOasPath(); + return apiPath.post["x-hyperledger-cacti"].http.path; + } + + public getVerbLowerCase(): string { + const apiPath = this.getOasPath(); + return apiPath.post["x-hyperledger-cacti"].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 fnTag = `${this.className}#handleRequest()`; + const reqTag = `${this.getVerbLowerCase()} - ${this.getPath()}`; + this.log.debug(reqTag); + try { + const { key } = req.body as DeleteKeychainEntryRequestV1; + const resBody = await this.options.plugin.delete(key); + res.json(resBody); + } catch (ex) { + const errorMsg = `${reqTag} ${fnTag} Failed to deploy contract:`; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); + } + } +} diff --git a/packages/cactus-plugin-keychain-memory/src/main/typescript/web-services/get-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-memory/src/main/typescript/web-services/get-keychain-entry-endpoint-v1.ts new file mode 100644 index 0000000000..ee8bb4fce4 --- /dev/null +++ b/packages/cactus-plugin-keychain-memory/src/main/typescript/web-services/get-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 { + GetKeychainEntryRequestV1, + IEndpointAuthzOptions, + IExpressRequestHandler, + IWebServiceEndpoint, +} from "@hyperledger/cactus-core-api"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; + +import OAS from "../../json/openapi.json"; +import { PluginKeychainMemory } from "../plugin-keychain-memory"; + +export interface IGetKeychainEntryEndpointOptions { + logLevel?: LogLevelDesc; + plugin: PluginKeychainMemory; +} + +export class GetKeychainEntryV1Endpoint implements IWebServiceEndpoint { + public static readonly CLASS_NAME = "GetKeychainEntryV1Endpoint"; + + private readonly log: Logger; + + public get className(): string { + return GetKeychainEntryV1Endpoint.CLASS_NAME; + } + + constructor(public readonly options: IGetKeychainEntryEndpointOptions) { + const fnTag = `${this.className}#constructor()`; + Checks.truthy(options, `${fnTag} arg options`); + Checks.truthy(options.plugin, `${fnTag} arg options.connector`); + + const level = this.options.logLevel || "INFO"; + const label = this.className; + this.log = LoggerProvider.getOrCreate({ level, label }); + } + + public getOasPath(): (typeof OAS.paths)["/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/get-keychain-entry"] { + return OAS.paths[ + "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/get-keychain-entry" + ]; + } + + public getPath(): string { + const apiPath = this.getOasPath(); + return apiPath.post["x-hyperledger-cacti"].http.path; + } + + public getVerbLowerCase(): string { + const apiPath = this.getOasPath(); + return apiPath.post["x-hyperledger-cacti"].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 fnTag = `${this.className}#handleRequest()`; + const reqTag = `${this.getVerbLowerCase()} - ${this.getPath()}`; + this.log.debug(reqTag); + try { + const { key } = req.body as GetKeychainEntryRequestV1; + const value = await this.options.plugin.get(key); + res.json({ key, value }); + } catch (ex) { + const errorMsg = `${reqTag} ${fnTag} Failed to deploy contract:`; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); + } + } +} diff --git a/packages/cactus-plugin-keychain-memory/src/main/typescript/web-services/has-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-memory/src/main/typescript/web-services/has-keychain-entry-endpoint-v1.ts new file mode 100644 index 0000000000..4b632f956a --- /dev/null +++ b/packages/cactus-plugin-keychain-memory/src/main/typescript/web-services/has-keychain-entry-endpoint-v1.ts @@ -0,0 +1,109 @@ +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 { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; + +import OAS from "../../json/openapi.json"; +import { PluginKeychainMemory } from "../plugin-keychain-memory"; +import { HasKeychainEntryRequestV1 } from "@hyperledger/cactus-core-api"; + +export interface IHasKeychainEntryEndpointOptions { + logLevel?: LogLevelDesc; + plugin: PluginKeychainMemory; +} + +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.plugin, `${fnTag} arg options.connector`); + + const level = this.options.logLevel || "INFO"; + const label = this.className; + this.log = LoggerProvider.getOrCreate({ level, label }); + } + + public getOasPath(): (typeof OAS.paths)["/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/has-keychain-entry"] { + return OAS.paths[ + "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/has-keychain-entry" + ]; + } + + public getPath(): string { + const apiPath = this.getOasPath(); + return apiPath.post["x-hyperledger-cacti"].http.path; + } + + public getVerbLowerCase(): string { + const apiPath = this.getOasPath(); + return apiPath.post["x-hyperledger-cacti"].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 fnTag = `${this.className}#handleRequest()`; + 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.plugin.has(key); + const resBody = { + isPresent, + key, + checkedAt, + }; + res.json(resBody); + } catch (ex) { + const errorMsg = `${reqTag} ${fnTag} Failed to deploy contract:`; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); + } + } +} diff --git a/packages/cactus-plugin-keychain-memory/src/main/typescript/web-services/set-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-memory/src/main/typescript/web-services/set-keychain-entry-endpoint-v1.ts new file mode 100644 index 0000000000..fdf32faac6 --- /dev/null +++ b/packages/cactus-plugin-keychain-memory/src/main/typescript/web-services/set-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 { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; + +import OAS from "../../json/openapi.json"; +import { PluginKeychainMemory } from "../plugin-keychain-memory"; +import { SetKeychainEntryRequestV1 } from "@hyperledger/cactus-core-api"; + +export interface ISetKeychainEntryEndpointOptions { + logLevel?: LogLevelDesc; + plugin: PluginKeychainMemory; +} + +export class SetKeychainEntryV1Endpoint implements IWebServiceEndpoint { + public static readonly CLASS_NAME = "SetKeychainEntryV1Endpoint"; + + private readonly log: Logger; + + public get className(): string { + return SetKeychainEntryV1Endpoint.CLASS_NAME; + } + + constructor(public readonly options: ISetKeychainEntryEndpointOptions) { + const fnTag = `${this.className}#constructor()`; + Checks.truthy(options, `${fnTag} arg options`); + Checks.truthy(options.plugin, `${fnTag} arg options.connector`); + + const level = this.options.logLevel || "INFO"; + const label = this.className; + this.log = LoggerProvider.getOrCreate({ level, label }); + } + + public getOasPath(): (typeof OAS.paths)["/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/set-keychain-entry"] { + return OAS.paths[ + "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-memory/set-keychain-entry" + ]; + } + + public getPath(): string { + const apiPath = this.getOasPath(); + return apiPath.post["x-hyperledger-cacti"].http.path; + } + + public getVerbLowerCase(): string { + const apiPath = this.getOasPath(); + return apiPath.post["x-hyperledger-cacti"].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 fnTag = `${this.className}#handleRequest()`; + const reqTag = `${this.getVerbLowerCase()} - ${this.getPath()}`; + this.log.debug(reqTag); + try { + const { key, value } = req.body as SetKeychainEntryRequestV1; + const resBody = await this.options.plugin.set(key, value); + res.json(resBody); + } catch (ex) { + const errorMsg = `${reqTag} ${fnTag} Failed to deploy contract:`; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); + } + } +} diff --git a/packages/cactus-plugin-keychain-memory/src/test/typescript/unit/plugin-keychain-memory-api-client.test.ts b/packages/cactus-plugin-keychain-memory/src/test/typescript/unit/plugin-keychain-memory-api-client.test.ts new file mode 100644 index 0000000000..402e1dd59d --- /dev/null +++ b/packages/cactus-plugin-keychain-memory/src/test/typescript/unit/plugin-keychain-memory-api-client.test.ts @@ -0,0 +1,143 @@ +import "jest-extended"; +import express from "express"; +import bodyParser from "body-parser"; +import http from "http"; +import { AddressInfo } from "net"; + +import { Bools, IListenOptions, Servers } from "@hyperledger/cactus-common"; + +import { v4 as uuidv4 } from "uuid"; +import { Configuration } from "@hyperledger/cactus-core-api"; + +import { + IPluginKeychainMemoryOptions, + DefaultApi as KeychainMemoryApi, + PluginKeychainMemory, +} from "../../../main/typescript/public-api"; + +describe("PluginKeychainMemory", () => { + let addressInfo: AddressInfo; + let httpServer: http.Server; + let expressApp: express.Express; + beforeAll(async () => { + expressApp = express(); + expressApp.use(bodyParser.json({ limit: "250mb" })); + + httpServer = http.createServer(expressApp); + const listenOptions: IListenOptions = { + hostname: "127.0.0.1", + port: 0, + server: httpServer, + }; + addressInfo = (await Servers.listen(listenOptions)) as AddressInfo; + }); + + afterAll(async () => { + await Servers.shutdown(httpServer); + }); + + it("has a constructor that works with valid parameters", () => { + expect( + () => + new PluginKeychainMemory({ + instanceId: "a", + keychainId: "a", + }), + ).not.toThrow(); + }); + + it("has a constructor that validates the instanceId", () => { + expect( + () => + new PluginKeychainMemory({ + instanceId: null as unknown as string, + keychainId: "valid-value", + }), + ).toThrow(); + + expect( + () => + new PluginKeychainMemory({ + instanceId: "", + keychainId: "valid-value", + }), + ).toThrow(); + }); + + it("has a constructor that validates the keychainId", () => { + expect( + () => + new PluginKeychainMemory({ + instanceId: "valid-value", + keychainId: null as unknown as string, + }), + ).toThrow(); + + expect( + () => + new PluginKeychainMemory({ + instanceId: "valid-value", + keychainId: "", + }), + ).toThrow(); + }); + + it("has get,set,has,delete ops which alter state as expected", async () => { + const instanceId = uuidv4(); + const keychainId = uuidv4(); + + const options: IPluginKeychainMemoryOptions = { + instanceId, + keychainId, + }; + const plugin = new PluginKeychainMemory(options); + + const { address, port } = addressInfo; + const apiHost = `http://${address}:${port}`; + + const config = new Configuration({ basePath: apiHost }); + const apiClient = new KeychainMemoryApi(config); + + await plugin.registerWebServices(expressApp); + + expect(plugin.getKeychainId()).toBe(options.keychainId); + expect(plugin.getInstanceId()).toBe(options.instanceId); + + const key1 = uuidv4(); + const value1 = uuidv4(); + + const hasPriorRes = await apiClient.hasKeychainEntryV1({ key: key1 }); + expect(hasPriorRes).toBeTruthy(); + expect(hasPriorRes.data).toBeTruthy(); + expect(Bools.isBooleanStrict(hasPriorRes.data.isPresent)).toBeTrue(); + + const hasPrior = hasPriorRes.data.isPresent; + expect(hasPrior).toBeFalse(); + + await plugin.set(key1, value1); + + const hasAfter1 = await plugin.has(key1); + expect(hasAfter1).toBeTrue(); + + const valueAfter1 = await plugin.get(key1); + expect(valueAfter1).toBeTruthy(); + expect(valueAfter1).toEqual(value1); + + await plugin.delete(key1); + + const hasAfterDelete1 = await plugin.has(key1); + expect(hasAfterDelete1).toBeFalse(); + + const key2 = uuidv4(); + const value2 = uuidv4(); + + await plugin.set(key2, value2); + + const hasAfter = await plugin.has(key2); + expect(hasAfter).toBeTrue(); + + const valueAfter2 = await plugin.get(key2); + expect(valueAfter2).toBeTruthy(); + expect(valueAfter2).toEqual(value2); + }); +}); diff --git a/packages/cactus-plugin-keychain-memory/src/test/typescript/unit/plugin-keychain-memory.test.ts b/packages/cactus-plugin-keychain-memory/src/test/typescript/unit/plugin-keychain-memory.test.ts index fd4eddaa1f..d80205e460 100644 --- a/packages/cactus-plugin-keychain-memory/src/test/typescript/unit/plugin-keychain-memory.test.ts +++ b/packages/cactus-plugin-keychain-memory/src/test/typescript/unit/plugin-keychain-memory.test.ts @@ -23,7 +23,7 @@ describe(testcase, () => { expressApp.use(bodyParser.json({ limit: "250mb" })); const server = http.createServer(expressApp); const listenOptions: IListenOptions = { - hostname: "localhost", + hostname: "127.0.0.1", port: 0, server, }; @@ -80,7 +80,8 @@ describe(testcase, () => { const config = new Configuration({ basePath: apiHost }); const apiClient = new KeychainMemoryApi(config); - await plugin.getOrCreateWebServices(expressApp); + await plugin.getOrCreateWebServices(); + await plugin.registerWebServices(expressApp); expect(plugin.getKeychainId()).toBe(options.keychainId); expect(plugin.getInstanceId()).toBe(options.instanceId);