Skip to content

Commit

Permalink
feat(plugin-keychain-memory): add ConnectRPC support
Browse files Browse the repository at this point in the history
1. This leverages the newly introduced methods in core-api that the API
server is using to probe if a plugin has ConnectRPC support or not.
2. There is support for both HTTP 1.1 and HTTP 2. The caveat here is that
HTTP 2 is not supported by ExpressJS so we pulled in Fastify to handle
those type of requests and that means that HTTP 2 ConnectRPC traffic has
to go through a different port compared to the HTTP 1.1 ConnectRPC traffic.
3. The lesson here is that we probably need to migrate away from ExpressJS
longer term because it does not (and from the looks of it will not ever)
support HTTP 2 which is probably going to be a bit of technical debt/
limiting factor in architectural decisions going forward for both Cacti
maintainers and Cacti users.
4. A new code generator has been introduced by this commit as well which
is @buf/build - the tool where ConnectRPC originates from. The scripts are
structured in such a way that this should be seamlessly integrated into the
existing `codegen` root level script and therefore also the CI.
5. There is test coverage for both HTTP 1.1 and HTTP 2 traffic in the file at
```sh
packages/cactus-test-plugin-keychain-memory/src/test/typescript/integration/
test-keychain-memory-crpc-api-server.test.ts
```
6. The test case referenced above is also the example on how to use the
ConnectRPC client (very similar to the HTTP client we already had before)

Depends on #3183

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
  • Loading branch information
petermetz committed Apr 11, 2024
1 parent 3cc33b1 commit c5fecf6
Show file tree
Hide file tree
Showing 44 changed files with 2,261 additions and 5 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,13 @@
"zod": ">=3.22.3"
},
"devDependencies": {
"@bufbuild/buf": "1.30.0",
"@bufbuild/protobuf": "1.8.0",
"@bufbuild/protoc-gen-es": "1.8.0",
"@commitlint/cli": "17.7.1",
"@commitlint/config-conventional": "17.7.0",
"@connectrpc/connect": "1.4.0",
"@connectrpc/protoc-gen-connect-es": "1.4.0",
"@lerna-lite/cli": "3.1.0",
"@lerna-lite/exec": "3.1.0",
"@lerna-lite/list": "3.1.0",
Expand Down
18 changes: 18 additions & 0 deletions packages/cactus-plugin-keychain-memory/buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# buf.gen.yaml defines a local generation template.
# For details, see https://buf.build/docs/configuration/v1/buf-gen-yaml
version: v1
plugins:
# This will invoke protoc-gen-es and write output to src/gen
- plugin: es
# packages/cactus-plugin-keychain-memory/src/main/typescript/generated/protoc-gen-es
out: ../../crpc
opt:
# Add more plugin options here
- target=ts
# This will invoke protoc-gen-connect-es
- plugin: connect-es
# packages/cactus-plugin-keychain-memory/src/main/typescript/generated/protoc-gen-connect-es
out: ../../crpc
opt:
# Add more plugin options here
- target=ts
15 changes: 12 additions & 3 deletions packages/cactus-plugin-keychain-memory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@
"dist/*"
],
"scripts": {
"codegen": "run-p 'codegen:*'",
"codegen": "yarn run --top-level run-s 'codegen:*'",
"codegen:openapi": "npm run generate-sdk",
"generate-sdk": "run-p 'generate-sdk:*'",
"codegen:proto": "run-s proto:openapi proto:crpc",
"generate-sdk": "run-s 'generate-sdk:*'",
"generate-sdk:kotlin": "openapi-generator-cli generate -i ./src/main/json/openapi.json -g kotlin -o ./src/main/kotlin/generated/openapi/kotlin-client/ --reserved-words-mappings protected=protected --ignore-file-override ../../openapi-generator-ignore",
"generate-sdk:typescript-axios": "openapi-generator-cli generate -i ./src/main/json/openapi.json -g typescript-axios -o ./src/main/typescript/generated/openapi/typescript-axios/ --reserved-words-mappings protected=protected --ignore-file-override ../../openapi-generator-ignore",
"proto:crpc": "yarn run --top-level buf generate --debug --verbose --template=./buf.gen.yaml --output ./src/main/typescript/generated/proto/crpc/ ./src/main/proto/generated/openapi/",
"proto:openapi": "yarn run --top-level openapi-generator-cli generate -i ./src/main/json/openapi.json -g protobuf-schema --model-name-suffix=PB --language-specific-primitives=google.protobuf.Any --type-mappings=AnyType=google.protobuf.Any --type-mappings=object=google.protobuf.Any --additional-properties=packageName=org.hyperledger.cacti.plugin.keychain.memory -o ./src/main/proto/generated/openapi/ -t=./src/main/mustache/openapi-generator/templates/protobuf-schema/ --ignore-file-override ../../openapi-generator-ignore",
"watch": "npm-watch",
"webpack": "npm-run-all webpack:dev",
"webpack:dev": "npm-run-all webpack:dev:node webpack:dev:web",
Expand All @@ -64,9 +67,15 @@
"uuid": "9.0.1"
},
"devDependencies": {
"@bufbuild/buf": "1.30.0",
"@bufbuild/protobuf": "1.8.0",
"@bufbuild/protoc-gen-es": "1.8.0",
"@connectrpc/connect": "1.4.0",
"@connectrpc/protoc-gen-connect-es": "1.4.0",
"@types/body-parser": "1.19.4",
"@types/express": "4.17.19",
"body-parser": "1.20.2"
"body-parser": "1.20.2",
"npm-run-all2": "6.1.2"
},
"engines": {
"node": ">=18",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{{>partial_header}}
syntax = "proto3";

package {{#lambda.lowercase}}{{{packageName}}}.{{{apiPackage}}}.{{{classname}}};{{/lambda.lowercase}}

import "google/protobuf/empty.proto";
{{#imports}}
{{#import}}
import "{{{modelPackage}}}/{{{.}}}.proto";
{{/import}}
{{/imports}}

service {{classname}} {
{{#operations}}
{{#operation}}
{{#description}}
// {{{.}}}
{{/description}}
rpc {{operationId}} ({{#hasParams}}{{operationId}}Request{{/hasParams}}{{^hasParams}}google.protobuf.Empty{{/hasParams}}) returns ({{#vendorExtensions.x-grpc-response}}{{.}}{{/vendorExtensions.x-grpc-response}}{{^vendorExtensions.x-grpc-response}}{{operationId}}Response{{/vendorExtensions.x-grpc-response}});

{{/operation}}
{{/operations}}
}

{{#operations}}
{{#operation}}
{{#hasParams}}
message {{operationId}}Request {
{{#allParams}}
{{#description}}
// {{{.}}}
{{/description}}
{{#vendorExtensions.x-protobuf-type}}{{.}} {{/vendorExtensions.x-protobuf-type}}{{vendorExtensions.x-protobuf-data-type}} {{paramName}} = {{vendorExtensions.x-protobuf-index}};
{{/allParams}}

}

{{/hasParams}}
{{^vendorExtensions.x-grpc-response}}
message {{operationId}}Response {
{{{vendorExtensions.x-grpc-response-type}}} data = 1;
}

{{/vendorExtensions.x-grpc-response}}
{{/operation}}
{{/operations}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{{>partial_header}}
syntax = "proto3";

package {{#lambda.lowercase}}{{{packageName}}};{{/lambda.lowercase}}

import "google/protobuf/any.proto";

{{#imports}}
{{#import}}
import "{{{modelPackage}}}/{{{import}}}.proto";
{{/import}}
{{/imports}}

{{#models}}
{{#model}}
{{#isEnum}}{{>enum}}{{/isEnum}}{{^isEnum}}message {{classname}} {
{{#vars}}
{{#description}}
// {{{.}}}
{{/description}}
{{^isEnum}}
{{#vendorExtensions.x-protobuf-type}}{{{.}}} {{/vendorExtensions.x-protobuf-type}}{{{vendorExtensions.x-protobuf-data-type}}} {{{name}}} = {{vendorExtensions.x-protobuf-index}}{{#vendorExtensions.x-protobuf-packed}} [packed=true]{{/vendorExtensions.x-protobuf-packed}};
{{/isEnum}}
{{#isEnum}}
enum {{enumName}} {
{{#allowableValues}}
{{#enumVars}}
{{{name}}} = {{{protobuf-enum-index}}};
{{/enumVars}}
{{/allowableValues}}
}

{{enumName}} {{name}} = {{vendorExtensions.x-protobuf-index}};
{{/isEnum}}

{{/vars}}
}
{{/isEnum}}
{{/model}}
{{/models}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{>partial_header}}
syntax = "proto3";

package {{{packageName}}};

{{#vendorExtensions.x-grpc-options}}
option {{{.}}};
{{/vendorExtensions.x-grpc-options}}

// Models
{{#models}}
{{#model}}
import "{{modelPackage}}/{{classFilename}}.proto";
{{/model}}
{{/models}}

// APIs
{{#apiInfo}}
{{#apis}}
import "{{apiPackage}}/{{classFilename}}.proto";
{{/apis}}
{{/apiInfo}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
README.md
models/delete_keychain_entry_request_v1_pb.proto
models/delete_keychain_entry_response_v1_pb.proto
models/get_keychain_entry_request_v1_pb.proto
models/get_keychain_entry_response_v1_pb.proto
models/has_keychain_entry_request_v1_pb.proto
models/has_keychain_entry_response_v1_pb.proto
models/set_keychain_entry_request_v1_pb.proto
models/set_keychain_entry_response_v1_pb.proto
services/default_service.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.6.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# gPRC for org.hyperledger.cacti.plugin.keychain.memory

Contains/describes the Hyperledger Cacti Keychain Memory plugin.

## Overview
These files were generated by the [OpenAPI Generator](https://openapi-generator.tech) project.

- API version: v2.0.0-alpha.2
- Package version:
- Build package: org.openapitools.codegen.languages.ProtobufSchemaCodegen

## Usage

Below are some usage examples for Go and Ruby. For other languages, please refer to https://grpc.io/docs/quickstart/.

### Go
```
# assuming `protoc-gen-go` has been installed with `go get -u github.com/golang/protobuf/protoc-gen-go`
mkdir /var/tmp/go/org.hyperledger.cacti.plugin.keychain.memory
protoc --go_out=/var/tmp/go/org.hyperledger.cacti.plugin.keychain.memory services/*
protoc --go_out=/var/tmp/go/org.hyperledger.cacti.plugin.keychain.memory models/*
```

### Ruby
```
# assuming `grpc_tools_ruby_protoc` has been installed via `gem install grpc-tools`
RUBY_OUTPUT_DIR="/var/tmp/ruby/org.hyperledger.cacti.plugin.keychain.memory"
mkdir $RUBY_OUTPUT_DIR
grpc_tools_ruby_protoc --ruby_out=$RUBY_OUTPUT_DIR --grpc_out=$RUBY_OUTPUT_DIR/lib services/*
grpc_tools_ruby_protoc --ruby_out=$RUBY_OUTPUT_DIR --grpc_out=$RUBY_OUTPUT_DIR/lib models/*
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
Hyperledger Cactus Plugin - Keychain Memory
Contains/describes the Hyperledger Cacti Keychain Memory plugin.
The version of the OpenAPI document: v2.0.0-alpha.2
Generated by OpenAPI Generator: https://openapi-generator.tech
*/

syntax = "proto3";

package org.hyperledger.cacti.plugin.keychain.memory;

import "google/protobuf/any.proto";


message DeleteKeychainEntryRequestV1PB {

// The key for the entry to check the presence of on the keychain.
string key = 106079;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
Hyperledger Cactus Plugin - Keychain Memory
Contains/describes the Hyperledger Cacti Keychain Memory plugin.
The version of the OpenAPI document: v2.0.0-alpha.2
Generated by OpenAPI Generator: https://openapi-generator.tech
*/

syntax = "proto3";

package org.hyperledger.cacti.plugin.keychain.memory;

import "google/protobuf/any.proto";


message DeleteKeychainEntryResponseV1PB {

// The key that was deleted from the keychain.
string key = 106079;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
Hyperledger Cactus Plugin - Keychain Memory
Contains/describes the Hyperledger Cacti Keychain Memory plugin.
The version of the OpenAPI document: v2.0.0-alpha.2
Generated by OpenAPI Generator: https://openapi-generator.tech
*/

syntax = "proto3";

package org.hyperledger.cacti.plugin.keychain.memory;

import "google/protobuf/any.proto";


message GetKeychainEntryRequestV1PB {

// The key for the entry to get from the keychain.
string key = 106079;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Hyperledger Cactus Plugin - Keychain Memory
Contains/describes the Hyperledger Cacti Keychain Memory plugin.
The version of the OpenAPI document: v2.0.0-alpha.2
Generated by OpenAPI Generator: https://openapi-generator.tech
*/

syntax = "proto3";

package org.hyperledger.cacti.plugin.keychain.memory;

import "google/protobuf/any.proto";


message GetKeychainEntryResponseV1PB {

// The key that was used to retrieve the value from the keychain.
string key = 106079;

// The value associated with the requested key on the keychain.
string value = 111972721;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
Hyperledger Cactus Plugin - Keychain Memory
Contains/describes the Hyperledger Cacti Keychain Memory plugin.
The version of the OpenAPI document: v2.0.0-alpha.2
Generated by OpenAPI Generator: https://openapi-generator.tech
*/

syntax = "proto3";

package org.hyperledger.cacti.plugin.keychain.memory;

import "google/protobuf/any.proto";


message HasKeychainEntryRequestV1PB {

// The key to check for presence in the keychain.
string key = 106079;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Hyperledger Cactus Plugin - Keychain Memory
Contains/describes the Hyperledger Cacti Keychain Memory plugin.
The version of the OpenAPI document: v2.0.0-alpha.2
Generated by OpenAPI Generator: https://openapi-generator.tech
*/

syntax = "proto3";

package org.hyperledger.cacti.plugin.keychain.memory;

import "google/protobuf/any.proto";


message HasKeychainEntryResponseV1PB {

// The key that was used to check the presence of the value in the entry store.
string key = 106079;

// Date and time encoded as JSON when the presence check was performed by the plugin backend.
string checkedAt = 399084090;

// The boolean true or false indicating the presence or absence of an entry under 'key'.
bool isPresent = 361185232;

}
Loading

0 comments on commit c5fecf6

Please sign in to comment.