Skip to content

Commit aee28fe

Browse files
outSHpetermetz
authored andcommitted
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. - Peter: Fixed missing dependency declarations - Peter: Consolidated the socket.io versions to the main branch - Peter: Fixed merge conflicts in yarn.lock file Closes: #2455 Co-authored-by: Peter Somogyvari <[email protected]> Signed-off-by: Michal Bajer <[email protected]> Signed-off-by: Peter Somogyvari <[email protected]>
1 parent 2570c81 commit aee28fe

File tree

17 files changed

+1364
-45
lines changed

17 files changed

+1364
-45
lines changed

jest.config.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# TODO
2+
# Install connector as yarn package like in @hyperledger/cactus-plugin-ledger-connector-besu
3+
4+
FROM node:18
5+
6+
WORKDIR /root/cactus/
7+
8+
COPY ./dist ./dist/
9+
COPY ./dist/yarn.lock ./package.json ./
10+
RUN yarn install --production --ignore-engines --non-interactive --cache-folder ./.yarnCache; rm -rf ./.yarnCache
11+
12+
EXPOSE 5061
13+
CMD [ "npm", "run", "start" ]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# `@hyperledger/cactus-plugin-ledger-connector-cdl-socketio`
2+
3+
This plugin provides `Cacti` a way to interact with Fujitsu CDL networks. Using this we can perform:
4+
5+
- `sendSyncRequest`: Send sync-typed requests to the API.
6+
- `sendAsyncRequest`: Send async-typed requests to the API.
7+
8+
## Getting started
9+
10+
### Required software components
11+
12+
- OS: Linux (recommended Ubuntu20.04,18.04 or CentOS7)
13+
- Docker (recommend: v17.06.2-ce or greater)
14+
- node.js v12 (recommend: v12.20.2 or greater)
15+
16+
## Boot methods
17+
18+
### Common setup
19+
20+
1. Always run configure command first, from the project root directory:
21+
22+
```bash
23+
pushd ../..
24+
npm run configure
25+
popd
26+
```
27+
28+
1. Copy default configuration
29+
30+
- **Remember to replace default CA and to adjust the `default.yaml` configuration on production deployments!**
31+
```bash
32+
mkdir -p /etc/cactus/connector-cdl-socketio
33+
rm -r /etc/cactus/connector-cdl-socketio/*
34+
cp -rf ./sample-config/* /etc/cactus/connector-cdl-socketio/
35+
```
36+
37+
#### Configuring CDL API Gateway Access
38+
39+
- Set the base URL of GW service in `cdlApiGateway.url`. Do not include `api/v1`, just the base URL. (example: `"http://localhost:3000"`).
40+
- If the service certificate is signed with a known CA (node uses Mozilla DB), then you can skip the next steps.
41+
- If the service is signed with unknown CA, you can specify the gateway certificate to trust manually:
42+
- Set `cdlApiGateway.caPath` to path of API Gateway certificate (in PEM format). (example: `"/etc/cactus/connector-cdl-socketio/CA/cdl-api-gateway-ca.pem"`)
43+
- (optional) If server name in cert doesn't match the one in `cdlApiGateway.url`, you can overwrite it in `cdlApiGateway.serverName`
44+
- (not recommended - only for development): To ignore certificate rejection (e.g. use self-signed certificate) set `cdlApiGateway.skipCertCheck` to `true`.
45+
46+
### Docker
47+
48+
- Docker build process will use artifacts from the latest build. Make sure `./dist` contains the version you want to dockerize.
49+
50+
```
51+
# Build
52+
DOCKER_BUILDKIT=1 docker build ./packages/cactus-plugin-ledger-connector-cdl-socketio -t cactus-plugin-ledger-connector-cdl-socketio
53+
54+
# Run
55+
docker run -v/etc/cactus/:/etc/cactus -p 5061:5061 cactus-plugin-ledger-connector-cdl-socketio
56+
```
57+
58+
### Manual
59+
60+
```
61+
npm run start
62+
```
63+
64+
## Configuration
65+
66+
- Validator can be configured in `/etc/cactus/connector-cdl-socketio/default.yaml` (see [sample-config](./sample-config/default.yaml) for details).
67+
68+
## Manual Tests
69+
70+
- There are no automatic tests for this plugin.
71+
- `cdl-connector-manual.test` contains a Jest test script that will check every implemented operation on a running CDL instance.
72+
- **You need access to a running instance of CDL in order to run this script.**
73+
- Before running the script you must update the following variables in it:
74+
- `ACCESS_TOKEN` - JWT token for authorization in CDL gateway.
75+
- `TOKEN_AGENT_ID` - Token agent ID.
76+
- `VALIDATOR_KEY_PATH` - Path to validator public certificate.
77+
- Script can be used as a quick reference for using this connector plugin.
78+
79+
## Contributing
80+
81+
We welcome contributions to Hyperledger Cacti in many forms, and there's always plenty to do!
82+
83+
Please review [CONTIRBUTING.md](../../CONTRIBUTING.md) to get started.
84+
85+
## License
86+
87+
This distribution is published under the Apache License Version 2.0 found in the [LICENSE](../../LICENSE) file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"name": "@hyperledger/cactus-plugin-ledger-connector-cdl-socketio",
3+
"version": "2.0.0-alpha.1",
4+
"description": "Allows Cacti nodes to connect to Fujitsu CDL.",
5+
"keywords": [
6+
"Hyperledger",
7+
"Cacti",
8+
"Integration",
9+
"Blockchain",
10+
"Distributed Ledger Technology"
11+
],
12+
"homepage": "https://github.com/hyperledger/cacti#readme",
13+
"bugs": {
14+
"url": "https://github.com/hyperledger/cacti/issues"
15+
},
16+
"repository": {
17+
"type": "git",
18+
"url": "git+https://github.com/hyperledger/cacti.git"
19+
},
20+
"license": "Apache-2.0",
21+
"author": {
22+
"name": "Hyperledger Cacti Contributors",
23+
"email": "[email protected]",
24+
"url": "https://www.hyperledger.org/use/cacti"
25+
},
26+
"contributors": [
27+
{
28+
"name": "Please add yourself to the list of contributors",
29+
"email": "[email protected]",
30+
"url": "https://example.com"
31+
},
32+
{
33+
"name": "Michal Bajer",
34+
"email": "[email protected]",
35+
"url": "https://www.fujitsu.com/global/"
36+
}
37+
],
38+
"main": "dist/index.js",
39+
"module": "dist/index.js",
40+
"types": "dist/index.d.ts",
41+
"files": [
42+
"dist/*"
43+
],
44+
"scripts": {
45+
"build": "npm run build-ts && npm run build:dev:backend:postbuild",
46+
"build-ts": "tsc",
47+
"build:dev:backend:postbuild": "npm run init-cdl",
48+
"debug": "nodemon --inspect ./dist/lib/main/typescript/common/core/bin/www.js",
49+
"init-cdl": "cp -af ../../yarn.lock ./dist/yarn.lock",
50+
"start": "node ./dist/lib/main/typescript/common/core/bin/www.js"
51+
},
52+
"dependencies": {
53+
"axios": "0.27.2",
54+
"body-parser": "1.20.2",
55+
"config": "3.3.7",
56+
"cookie-parser": "1.4.6",
57+
"express": "4.18.2",
58+
"fast-safe-stringify": "2.1.1",
59+
"http-errors": "1.6.3",
60+
"js-yaml": "3.14.1",
61+
"jsonwebtoken": "9.0.0",
62+
"log4js": "6.4.1",
63+
"sanitize-html": "2.7.0",
64+
"socket.io": "4.5.4"
65+
},
66+
"devDependencies": {
67+
"@hyperledger/cactus-api-client": "2.0.0-alpha.1",
68+
"@hyperledger/cactus-common": "2.0.0-alpha.1",
69+
"@types/config": "0.0.41",
70+
"@types/express": "4.17.13",
71+
"@types/node": "14.17.32",
72+
"@types/sanitize-html": "2.6.2",
73+
"jest-extended": "0.11.5",
74+
"uuid": "8.3.2"
75+
},
76+
"engines": {
77+
"node": ">=10",
78+
"npm": ">=6"
79+
},
80+
"publishConfig": {
81+
"access": "public"
82+
},
83+
"watch": {}
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
sslParam:
2+
port: 5061
3+
key: "/etc/cactus/connector-cdl-socketio/CA/connector.priv"
4+
cert: "/etc/cactus/connector-cdl-socketio/CA/connector.crt"
5+
logLevel: "debug"
6+
userAgent: "CactiCDLConnector"
7+
cdlApiGateway:
8+
url: "http://localhost:3000"
9+
#skipCertCheck: true # Set to true to ignore self-signed and other rejected certificates
10+
#caPath: "/etc/cactus/connector-cdl-socketio/CA/cdl-api-gateway-ca.pem" # CA of CDL API gateway server in PEM format to use
11+
#serverName: "cdl.fujitsu" # Overwrite server name from cdlApiGateway.url to match one specified in CA
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2023 Hyperledger Cacti Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* app.js
6+
*/
7+
8+
/* Summary:
9+
*
10+
*/
11+
12+
import { NextFunction, Request, Response } from "express";
13+
import createError from "http-errors";
14+
import express from "express";
15+
import cookieParser from "cookie-parser";
16+
import bodyParser from "body-parser";
17+
18+
const app: express.Express = express();
19+
20+
app.use(bodyParser.json());
21+
app.use(bodyParser.urlencoded({ extended: false }));
22+
app.use(cookieParser());
23+
24+
// catch 404 and forward to error handler
25+
app.use((req: Request, res: Response, next: NextFunction) => {
26+
next(createError(404));
27+
});
28+
29+
// error handler
30+
app.use(
31+
(
32+
err: { message: string; status?: number },
33+
req: Request,
34+
res: Response,
35+
next: NextFunction,
36+
) => {
37+
// set locals, only providing error in development
38+
res.locals.message = err.message;
39+
res.locals.error = req.app.get("env") === "development" ? err : {};
40+
41+
// set erreor response
42+
const errorResponse: {} = {
43+
statusCode: err.status || 500,
44+
message: err.message,
45+
};
46+
47+
// render the error page
48+
res.status(err.status || 500);
49+
res.send(errorResponse);
50+
},
51+
);
52+
53+
export default app;

0 commit comments

Comments
 (0)