Merge pull request #30 from p2p-org/cli_tool_support_tls
add TLS support
This commit is contained in:
@@ -1,21 +1,36 @@
|
|||||||
# DSHACKLE CLI
|
# DSHACKLE CLI
|
||||||
|
|
||||||
A CLI tool to verify the [dshacle](https://github.com/emeraldpay/dshackle) installation.
|
A CLI tool to verify the [dshackle](https://github.com/emeraldpay/dshackle) installation.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
```
|
```
|
||||||
npx dchackle-cli-tool [-p|--print] <dshackle instance url>
|
npx dshackle-cli-tool [-p|--print][--ca][--cert][--key] <dshackle instance url>
|
||||||
```
|
```
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
-p | --print - will print the describe response as is
|
```-p | --print``` will print the describe response as is
|
||||||
|
|
||||||
|
### TLS
|
||||||
|
```--ca``` the root certificate data
|
||||||
|
|
||||||
|
```--cert``` the client certificate key chain, if available
|
||||||
|
```--key``` the client certificate private key, if available
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
```
|
```
|
||||||
> dchackle-cli-tool localhost:2449
|
> dshackle-cli-tool localhost:2449
|
||||||
Connecting to: localhost:2449...
|
Connecting to: localhost:2449...
|
||||||
Connected to localhost:2449
|
Connected to localhost:2449
|
||||||
CHAIN_ETHEREUM -> AVAIL_OK
|
CHAIN_ETHEREUM -> AVAIL_OK
|
||||||
CHAIN_KOVAN -> AVAIL_OK
|
CHAIN_KOVAN -> AVAIL_OK
|
||||||
|
```
|
||||||
|
|
||||||
|
With TLS
|
||||||
|
```
|
||||||
|
>dshackle-cli % dshackle-cli-tool --ca ./../out/ca.myhost.dev.crt --cert ./../out/client_1.crt --key ./../out/client_1.key 127.0.0.1:2450
|
||||||
|
Using TLS
|
||||||
|
Connecting to: 127.0.0.1:2450...
|
||||||
|
Connected to 127.0.0.1:2450
|
||||||
|
CHAIN_ETHEREUM -> AVAIL_OK
|
||||||
```
|
```
|
||||||
4
dshackle-cli/package-lock.json
generated
4
dshackle-cli/package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "dshackle-cli-tool",
|
"name": "dshackle-cli-tool",
|
||||||
"version": "1.0.3",
|
"version": "1.0.7",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "dshackle-cli-tool",
|
"name": "dshackle-cli-tool",
|
||||||
"version": "1.0.3",
|
"version": "1.0.7",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@grpc/grpc-js": "^1.6.12",
|
"@grpc/grpc-js": "^1.6.12",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "dshackle-cli-tool",
|
"name": "dshackle-cli-tool",
|
||||||
"version": "1.0.4",
|
"version": "1.0.7",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ import util from "util";
|
|||||||
export function cli(args) {
|
export function cli(args) {
|
||||||
let opts = parseArgumentsIntoOptions(args);
|
let opts = parseArgumentsIntoOptions(args);
|
||||||
if (!opts.url) {
|
if (!opts.url) {
|
||||||
console.log("Err: URL not specified!")
|
console.log("Err: URL not specified!!!")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
describe(opts.url, (error, response) => {
|
describe(opts.url, opts.ca, opts.cert, opts.key, (error, response) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error(clc.red('Connection to ' + opts.url + ' failed! [' + error.message + ']'));
|
console.error(clc.red('Connection to ' + opts.url + ' failed! [' + error.message + ']'));
|
||||||
} else {
|
} else {
|
||||||
@@ -42,6 +42,9 @@ function parseArgumentsIntoOptions(rawArgs) {
|
|||||||
const args = arg(
|
const args = arg(
|
||||||
{
|
{
|
||||||
'--print': Boolean,
|
'--print': Boolean,
|
||||||
|
'--ca': String,
|
||||||
|
'--cert': String,
|
||||||
|
'--key': String,
|
||||||
'-p': '--print'
|
'-p': '--print'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -50,7 +53,10 @@ function parseArgumentsIntoOptions(rawArgs) {
|
|||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
print: args['--print'] || false,
|
print: args['--print'] || false,
|
||||||
url: args._[0]
|
url: args._[0],
|
||||||
|
ca: args['--ca'],
|
||||||
|
cert: args['--cert'],
|
||||||
|
key: args['--key']
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
const grpc = require("@grpc/grpc-js");
|
const grpc = require("@grpc/grpc-js");
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const protoLoader = require("@grpc/proto-loader");
|
const protoLoader = require("@grpc/proto-loader");
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
const PROTO_PATH = path.join(__dirname, "../grpc/proto/blockchain.proto");
|
const PROTO_PATH = path.join(__dirname, "../grpc/proto/blockchain.proto");
|
||||||
|
|
||||||
@@ -15,11 +16,21 @@ const options = {
|
|||||||
const packageDefinition = protoLoader.loadSync(PROTO_PATH, options);
|
const packageDefinition = protoLoader.loadSync(PROTO_PATH, options);
|
||||||
const emerald = grpc.loadPackageDefinition(packageDefinition).emerald
|
const emerald = grpc.loadPackageDefinition(packageDefinition).emerald
|
||||||
|
|
||||||
export function describe(url, handler) {
|
export function describe(url, ca, cert, key, handler) {
|
||||||
|
let credentials = grpc.credentials.createInsecure()
|
||||||
|
if (ca || cert || key) {
|
||||||
|
console.log("Using TLS")
|
||||||
|
credentials = grpc.credentials.createSsl(
|
||||||
|
ca ? fs.readFileSync(ca) : null,
|
||||||
|
key ? fs.readFileSync(key) : null,
|
||||||
|
cert ? fs.readFileSync(cert) : null
|
||||||
|
);
|
||||||
|
}
|
||||||
const client = new emerald.Blockchain(
|
const client = new emerald.Blockchain(
|
||||||
url,
|
url,
|
||||||
grpc.credentials.createInsecure()
|
credentials
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log('Connecting to: ' + url + '...')
|
console.log('Connecting to: ' + url + '...')
|
||||||
client.Describe({}, handler);
|
client.Describe({}, handler);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user