Skip to content

Commit

Permalink
feat(plugin-keychain-memory): add REST API endpoint implementations
Browse files Browse the repository at this point in the history
**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 <[email protected]>
  • Loading branch information
petermetz committed Dec 6, 2023
1 parent 358861d commit c7a8fa5
Show file tree
Hide file tree
Showing 25 changed files with 1,725 additions and 171 deletions.
238 changes: 113 additions & 125 deletions packages/cactus-plugin-keychain-memory/src/main/json/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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.


<a id="documentation-for-models"></a>
## 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)


<a id="documentation-for-authorization"></a>
Expand Down
Loading

0 comments on commit c7a8fa5

Please sign in to comment.