forked from hyperledger-cacti/cacti
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cactus-plugin-ledger-connector-cdl-socketio): add new connector …
…plugin - Add new plugin for connecting with Fujitsu CDL. - Add test script for checking connector operations manually. Closes: hyperledger-cacti#2455 Signed-off-by: Michal Bajer <[email protected]>
- Loading branch information
Showing
17 changed files
with
1,383 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
packages/cactus-plugin-ledger-connector-cdl-socketio/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# TODO | ||
# Install connector as yarn package like in @hyperledger/cactus-plugin-ledger-connector-besu | ||
|
||
FROM node:12 | ||
|
||
WORKDIR /root/cactus/ | ||
|
||
COPY ./dist ./dist/ | ||
COPY ./dist/yarn.lock ./package.json ./ | ||
RUN yarn install --production --ignore-engines --non-interactive --cache-folder ./.yarnCache; rm -rf ./.yarnCache | ||
|
||
EXPOSE 5061 | ||
CMD [ "npm", "run", "start" ] |
81 changes: 81 additions & 0 deletions
81
packages/cactus-plugin-ledger-connector-cdl-socketio/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# `@hyperledger/cactus-plugin-ledger-connector-cdl-socketio` | ||
|
||
This plugin provides `Cactus` a way to interact with Fujitsu CDL networks. Using this we can perform: | ||
|
||
- `sendSyncRequest`: Send sync-typed requests to the API. | ||
- `sendAsyncRequest`: Send async-typed requests to the API. | ||
|
||
## Getting started | ||
|
||
### Required software components | ||
|
||
- OS: Linux (recommended Ubuntu20.04,18.04 or CentOS7) | ||
- Docker (recommend: v17.06.2-ce or greater) | ||
- node.js v12 (recommend: v12.20.2 or greater) | ||
|
||
## Boot methods | ||
|
||
### Common setup | ||
|
||
1. Always run configure command first, from the project root directory: | ||
|
||
```bash | ||
pushd ../.. | ||
npm run configure | ||
popd | ||
``` | ||
|
||
1. Copy default configuration | ||
|
||
- **Remember to replace default CA and to adjust the `default.yaml` configuration on production deployments!** | ||
```bash | ||
mkdir -p /etc/cactus/connector-cdl-socketio | ||
rm -r /etc/cactus/connector-cdl-socketio/* | ||
cp -rf ./sample-config/* /etc/cactus/connector-cdl-socketio/ | ||
``` | ||
|
||
#### Configuring CDL API Gateway Access | ||
|
||
- Set the base URL of GW service in `cdlApiGateway.url`. Do not include `api/v1`, just the base URL. (example: `"http://localhost:3000"`). | ||
- If the service certificate is signed with a known CA (node uses Mozilla DB), then you can skip the next steps. | ||
- If the service is signed with unknown CA, you can specify the gateway certificate to trust manually: | ||
- Set `cdlApiGateway.caPath` to path of API Gateway certificate (in PEM format). (example: `"/etc/cactus/connector-cdl-socketio/CA/cdl-api-gateway-ca.pem"`) | ||
- (optional) If server name in cert doesn't match the one in `cdlApiGateway.url`, you can overwrite it in `cdlApiGateway.serverName` | ||
- (not recommended - only for development): To ignore certificate rejection (e.g. use self-signed certificate) set `cdlApiGateway.skipCertCheck` to `true`. | ||
### Docker | ||
- Docker build process will use artifacts from the latest build. Make sure `./dist` contains the version you want to dockerize. | ||
``` | ||
# Build | ||
docker build . -t cactus-plugin-ledger-connector-cdl-socketio | ||
# Run | ||
docker run -v/etc/cactus/:/etc/cactus -p 5061:5061 cactus-plugin-ledger-connector-cdl-socketio | ||
``` | ||
### Manual | ||
``` | ||
npm run start | ||
``` | ||
## Configuration | ||
- Validator can be configured in `/etc/cactus/connector-cdl-socketio/default.yaml` (see [sample-config](./sample-config/default.yaml) for details). | ||
## Manual Tests | ||
- `cdl-connector-manual.test` contains a Jest test script that will check every implemented operation on running CDL instance. | ||
- Script can be used as a quick reference for using this connector plugin. | ||
## Contributing | ||
We welcome contributions to Hyperledger Cactus in many forms, and there's always plenty to do! | ||
|
||
Please review [CONTIRBUTING.md](../../CONTRIBUTING.md) to get started. | ||
|
||
## License | ||
|
||
This distribution is published under the Apache License Version 2.0 found in the [LICENSE](../../LICENSE) file. |
81 changes: 81 additions & 0 deletions
81
packages/cactus-plugin-ledger-connector-cdl-socketio/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
{ | ||
"name": "@hyperledger/cactus-plugin-ledger-connector-cdl-socketio", | ||
"version": "2.0.0-alpha.1", | ||
"description": "Allows Cactus nodes to connect to a Besu ledger.", | ||
"keywords": [ | ||
"Hyperledger", | ||
"Cactus", | ||
"Integration", | ||
"Blockchain", | ||
"Distributed Ledger Technology" | ||
], | ||
"homepage": "https://github.com/hyperledger/cacti#readme", | ||
"bugs": { | ||
"url": "https://github.com/hyperledger/cacti/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/hyperledger/cacti.git" | ||
}, | ||
"license": "Apache-2.0", | ||
"author": { | ||
"name": "Hyperledger Cactus Contributors", | ||
"email": "[email protected]", | ||
"url": "https://www.hyperledger.org/use/cactus" | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "Please add yourself to the list of contributors", | ||
"email": "[email protected]", | ||
"url": "https://example.com" | ||
}, | ||
{ | ||
"name": "Michal Bajer", | ||
"email": "[email protected]", | ||
"url": "https://www.fujitsu.com/global/" | ||
} | ||
], | ||
"main": "dist/index.js", | ||
"module": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist/*" | ||
], | ||
"scripts": { | ||
"build": "npm run build-ts && npm run build:dev:backend:postbuild", | ||
"build-ts": "tsc", | ||
"build:dev:backend:postbuild": "npm run init-cdl", | ||
"debug": "nodemon --inspect ./dist/common/core/bin/www.js", | ||
"init-cdl": "cp -af ../../yarn.lock ./dist/yarn.lock", | ||
"start": "cd ./dist && node common/core/bin/www.js" | ||
}, | ||
"dependencies": { | ||
"axios": "0.27.2", | ||
"body-parser": "1.17.2", | ||
"config": "3.3.7", | ||
"cookie-parser": "1.4.6", | ||
"express": "4.15.5", | ||
"fast-safe-stringify": "2.1.1", | ||
"http-errors": "1.6.3", | ||
"js-yaml": "3.14.1", | ||
"jsonwebtoken": "8.5.1", | ||
"log4js": "6.4.1", | ||
"sanitize-html": "2.7.0", | ||
"socket.io": "4.4.1" | ||
}, | ||
"devDependencies": { | ||
"@types/config": "0.0.41", | ||
"@types/node": "14.17.32", | ||
"@types/sanitize-html": "2.6.2", | ||
"jest-extended": "0.11.5", | ||
"uuid": "8.3.2" | ||
}, | ||
"engines": { | ||
"node": ">=10", | ||
"npm": ">=6" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"watch": {} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/cactus-plugin-ledger-connector-cdl-socketio/sample-config/default.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
sslParam: | ||
port: 5061 | ||
key: "/etc/cactus/connector-cdl-socketio/CA/connector.priv" | ||
cert: "/etc/cactus/connector-cdl-socketio/CA/connector.crt" | ||
logLevel: "debug" | ||
userAgent: "CactusCDLConnector" | ||
cdlApiGateway: | ||
url: "http://localhost:3000" | ||
#skipCertCheck: true # Set to true to ignore self-signed and other rejected certificates | ||
#caPath: "/etc/cactus/connector-cdl-socketio/CA/cdl-api-gateway-ca.pem" # CA of CDL API gateway server in PEM format to use | ||
#serverName: "cdl.fujitsu" # Overwrite server name from cdlApiGateway.url to match one specified in CA |
53 changes: 53 additions & 0 deletions
53
packages/cactus-plugin-ledger-connector-cdl-socketio/src/main/typescript/common/core/app.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2021 Hyperledger Cactus Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* app.js | ||
*/ | ||
|
||
/* Summary: | ||
* | ||
*/ | ||
|
||
import { NextFunction, Request, Response } from "express"; | ||
import createError from "http-errors"; | ||
import express from "express"; | ||
import cookieParser from "cookie-parser"; | ||
import bodyParser from "body-parser"; | ||
|
||
const app: express.Express = express(); | ||
|
||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({ extended: false })); | ||
app.use(cookieParser()); | ||
|
||
// catch 404 and forward to error handler | ||
app.use((req: Request, res: Response, next: NextFunction) => { | ||
next(createError(404)); | ||
}); | ||
|
||
// error handler | ||
app.use( | ||
( | ||
err: { message: string; status?: number }, | ||
req: Request, | ||
res: Response, | ||
next: NextFunction, | ||
) => { | ||
// set locals, only providing error in development | ||
res.locals.message = err.message; | ||
res.locals.error = req.app.get("env") === "development" ? err : {}; | ||
|
||
// set erreor response | ||
const errorResponse: {} = { | ||
statusCode: err.status || 500, | ||
message: err.message, | ||
}; | ||
|
||
// render the error page | ||
res.status(err.status || 500); | ||
res.send(errorResponse); | ||
}, | ||
); | ||
|
||
export default app; |
Oops, something went wrong.