Skip to content

Commit

Permalink
feat(cmd-api-server): support grpc web services hyperledger#1189
Browse files Browse the repository at this point in the history
TODO:
1. Figure out how to stop the generator from mangling the model
property names into capital case (getCreatedat)
See: https://github.com/protocolbuffers/protobuf/issues/8608

2. Figure out how to export the OpenAPI model classes and the
gRPC model classes at the same time without name conflicts
(they have the same names)

3. Implement streaming healthcheck endpiont with gRPC

4. Allow plugins to hook in their own gRPC service implementations.

5. Verify with test case that the secure credentials flavor also
works.

Fixes hyperledger#1189

Signed-off-by: Peter Somogyvari <[email protected]>
  • Loading branch information
petermetz committed Aug 11, 2021
1 parent 0e4c7c5 commit 0638005
Show file tree
Hide file tree
Showing 35 changed files with 1,707 additions and 46 deletions.
11 changes: 9 additions & 2 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"gopath",
"grpc",
"grpcs",
"grpcwebtext",
"hashicorp",
"Healthcheck",
"HTLC",
Expand Down Expand Up @@ -68,10 +69,17 @@
"NODETXPOOLACK",
"notok",
"Oidc",
"oneofs",
"onsi",
"OpenAPI",
"openethereum",
"organisation",
"parameterizable",
"pbjs",
"pbts",
"proto",
"protobuf",
"protoc",
"protos",
"RUSTC",
"Secp",
Expand All @@ -91,8 +99,7 @@
"uuidv",
"vscc",
"wasm",
"Xdai",
"parameterizable"
"Xdai"
],
"dictionaries": [
"typescript,node,npm,go,rust"
Expand Down
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
# **/coverage/**

# typings/**

**/src/main/typescript/generated/proto/**
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"@angular/compiler-cli": "12.1.1",
"@angular/language-service": "12.1.1",
"@ionic/angular-toolkit": "2.3.0",
"@types/jasminewd2": "2.0.3",
"@types/node": "12.11.1",
"codelyzer": "6.0.2",
"jasmine-core": "3.6.0",
Expand Down
1 change: 0 additions & 1 deletion examples/cactus-example-supply-chain-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"@angular/compiler-cli": "12.1.1",
"@angular/language-service": "12.1.1",
"@ionic/angular-toolkit": "2.3.0",
"@types/jasminewd2": "2.0.3",
"@types/node": "12.11.1",
"codelyzer": "6.0.2",
"jasmine-core": "3.6.0",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
"@commitlint/config-conventional": "8.0.0",
"@openapitools/openapi-generator-cli": "2.3.3",
"@types/fs-extra": "9.0.11",
"@types/jasminewd2": "2.0.10",
"@types/node-fetch": "2.5.4",
"@types/tape": "4.13.0",
"@types/tape-promise": "4.0.1",
Expand All @@ -100,6 +99,8 @@
"fs-extra": "10.0.0",
"git-cz": "4.7.6",
"globby": "10.0.2",
"grpc-tools": "1.11.2",
"grpc_tools_node_protoc_ts": "5.3.1",
"husky": "4.2.5",
"inquirer": "8.1.1",
"json5": "2.2.0",
Expand Down
8 changes: 7 additions & 1 deletion packages/cactus-cmd-api-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
"browser": "dist/cactus-cmd-api-server.web.umd.js",
"browserMinified": "dist/cactus-cmd-api-server.web.umd.min.js",
"module": "dist/lib/main/typescript/index.js",
"types": "dist/types/main/typescript/index.d.ts",
"types": "dist/lib/main/typescript/index.d.ts",
"scripts": {
"generate-sdk": "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",
"codegen:openapi": "npm run generate-sdk",
"proto:openapi": "openapi-generator-cli generate -i ./src/main/json/openapi.json -g protobuf-schema --additional-properties=packageName=org.hyperledger.cactus.cmd_api_server -o ./src/main/proto/generated/openapi/",
"proto:protoc-gen-ts": "yarn run grpc_tools_node_protoc --plugin=protoc-gen-ts=../../node_modules/.bin/protoc-gen-ts --js_out=import_style=commonjs,binary:./src/main/typescript/generated/proto/protoc-gen-ts/ --ts_out=grpc_js:./src/main/typescript/generated/proto/protoc-gen-ts/ --grpc_out=grpc_js:./src/main/typescript/generated/proto/protoc-gen-ts/ --proto_path ./src/main/proto/generated/openapi/ --proto_path ./src/main/proto/generated/openapi/models/ --proto_path ./src/main/proto/generated/openapi/services/ ./src/main/proto/generated/openapi/models/*.proto ./src/main/proto/generated/openapi/services/*.proto",
"codegen:proto": "run-s proto:openapi proto:protoc-gen-ts",
"codegen": "run-p 'codegen:*'",
"watch": "npm-watch",
"webpack": "npm-run-all webpack:dev webpack:prod",
Expand Down Expand Up @@ -72,6 +75,8 @@
},
"homepage": "https://github.com/hyperledger/cactus#readme",
"dependencies": {
"@grpc/grpc-js": "1.3.6",
"@grpc/proto-loader": "0.6.4",
"@hyperledger/cactus-common": "0.7.0",
"@hyperledger/cactus-core": "0.7.0",
"@hyperledger/cactus-core-api": "0.7.0",
Expand Down Expand Up @@ -108,6 +113,7 @@
"@types/express": "4.17.8",
"@types/express-http-proxy": "1.6.1",
"@types/express-jwt": "6.0.1",
"@types/google-protobuf": "3.15.3",
"@types/jsonwebtoken": "8.5.1",
"@types/multer": "1.4.5",
"@types/node-forge": "0.9.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
README.md
models/health_check_response.proto
models/memory_usage.proto
models/watch_healthcheck_v1.proto
services/default_service.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.1.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# gPRC for org.hyperledger.cactus.cmd_api_server

Interact with a Cactus deployment through HTTP.

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

- API version: 0.0.1
- 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/
protoc --go_out=/var/tmp/go/ services/*
protoc --go_out=/var/tmp/go/ models/*
```

### Ruby
```
# assuming `grpc_tools_ruby_protoc` has been installed via `gem install grpc-tools`
RUBY_OUTPUT_DIR="/var/tmp/ruby/org.hyperledger.cactus.cmd_api_server"
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,25 @@
/*
Hyperledger Cactus API
Interact with a Cactus deployment through HTTP.
The version of the OpenAPI document: 0.0.1
Generated by OpenAPI Generator: https://openapi-generator.tech
*/

syntax = "proto3";

package org.hyperledger.cactus.cmd_api_server;

import public "models/memory_usage.proto";

message HealthCheckResponse {

bool success = 256557056;

string createdAt = 61500732;

MemoryUsage memoryUsage = 335792418;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Hyperledger Cactus API
Interact with a Cactus deployment through HTTP.
The version of the OpenAPI document: 0.0.1
Generated by OpenAPI Generator: https://openapi-generator.tech
*/

syntax = "proto3";

package org.hyperledger.cactus.cmd_api_server;


message MemoryUsage {

float rss = 113234;

float heapTotal = 114487480;

float heapUsed = 30910521;

float external = 210148408;

float arrayBuffers = 116952168;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Hyperledger Cactus API
Interact with a Cactus deployment through HTTP.
The version of the OpenAPI document: 0.0.1
Generated by OpenAPI Generator: https://openapi-generator.tech
*/

syntax = "proto3";

package org.hyperledger.cactus.cmd_api_server;


message WatchHealthcheckV1 {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Hyperledger Cactus API
Interact with a Cactus deployment through HTTP.
The version of the OpenAPI document: 0.0.1
Generated by OpenAPI Generator: https://openapi-generator.tech
*/

syntax = "proto3";

package org.hyperledger.cactus.cmd_api_server;

import "google/protobuf/empty.proto";
import public "models/health_check_response.proto";

service DefaultService {
rpc GetHealthCheckV1 (google.protobuf.Empty) returns (HealthCheckResponse);

rpc GetPrometheusMetricsV1 (google.protobuf.Empty) returns (GetPrometheusMetricsV1Response);

}

message GetPrometheusMetricsV1Response {
string data = 1;
}

Loading

0 comments on commit 0638005

Please sign in to comment.