-
Notifications
You must be signed in to change notification settings - Fork 285
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. - 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 <peter.somogyvari@accenture.com> Signed-off-by: Michal Bajer <michal.bajer@fujitsu.com> Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
- Loading branch information
Showing
17 changed files
with
1,364 additions
and
45 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:18 | ||
|
||
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" ] |
87 changes: 87 additions & 0 deletions
87
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,87 @@ | ||
# `@hyperledger/cactus-plugin-ledger-connector-cdl-socketio` | ||
|
||
This plugin provides `Cacti` 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_BUILDKIT=1 docker build ./packages/cactus-plugin-ledger-connector-cdl-socketio -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 | ||
|
||
- There are no automatic tests for this plugin. | ||
- `cdl-connector-manual.test` contains a Jest test script that will check every implemented operation on a running CDL instance. | ||
- **You need access to a running instance of CDL in order to run this script.** | ||
- Before running the script you must update the following variables in it: | ||
- `ACCESS_TOKEN` - JWT token for authorization in CDL gateway. | ||
- `TOKEN_AGENT_ID` - Token agent ID. | ||
- `VALIDATOR_KEY_PATH` - Path to validator public certificate. | ||
- Script can be used as a quick reference for using this connector plugin. | ||
|
||
## Contributing | ||
|
||
We welcome contributions to Hyperledger Cacti 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. |
84 changes: 84 additions & 0 deletions
84
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,84 @@ | ||
{ | ||
"name": "@hyperledger/cactus-plugin-ledger-connector-cdl-socketio", | ||
"version": "2.0.0-alpha.1", | ||
"description": "Allows Cacti nodes to connect to Fujitsu CDL.", | ||
"keywords": [ | ||
"Hyperledger", | ||
"Cacti", | ||
"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 Cacti Contributors", | ||
"email": "cacti@lists.hyperledger.org", | ||
"url": "https://www.hyperledger.org/use/cacti" | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "Please add yourself to the list of contributors", | ||
"email": "your.name@example.com", | ||
"url": "https://example.com" | ||
}, | ||
{ | ||
"name": "Michal Bajer", | ||
"email": "michal.bajer@fujitsu.com", | ||
"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/lib/main/typescript/common/core/bin/www.js", | ||
"init-cdl": "cp -af ../../yarn.lock ./dist/yarn.lock", | ||
"start": "node ./dist/lib/main/typescript/common/core/bin/www.js" | ||
}, | ||
"dependencies": { | ||
"axios": "0.27.2", | ||
"body-parser": "1.20.2", | ||
"config": "3.3.7", | ||
"cookie-parser": "1.4.6", | ||
"express": "4.18.2", | ||
"fast-safe-stringify": "2.1.1", | ||
"http-errors": "1.6.3", | ||
"js-yaml": "3.14.1", | ||
"jsonwebtoken": "9.0.0", | ||
"log4js": "6.4.1", | ||
"sanitize-html": "2.7.0", | ||
"socket.io": "4.5.4" | ||
}, | ||
"devDependencies": { | ||
"@hyperledger/cactus-api-client": "2.0.0-alpha.1", | ||
"@hyperledger/cactus-common": "2.0.0-alpha.1", | ||
"@types/config": "0.0.41", | ||
"@types/express": "4.17.13", | ||
"@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: "CactiCDLConnector" | ||
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 2023 Hyperledger Cacti 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.