From c247fa3157da5701aafb299ce72d21a94329cfee Mon Sep 17 00:00:00 2001 From: Giovanni Angoli Date: Mon, 1 Jan 2018 19:03:57 +0100 Subject: [PATCH] feat: Added -k switch for self signed certificates, cli parameters cleanup (#7) * added -k switch to use self signed certs w/tls, cleaned up cli parameters (-l logging and -h help) * changed condition check with more compact code --- README.md | 5 +++-- src/bridge.js | 3 ++- src/config.js | 8 +++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9b480db..50fbd95 100644 --- a/README.md +++ b/README.md @@ -36,10 +36,11 @@ Options: -d, --devices File location of device list (must end with .json). -g, --password Gateway password (to enable gateway light change) -h, --help Show help - -l, --logging possiblevalues: "error", "warn","info","debug" - [default: "info"] + -l, --logging Logging level [choices: "error", "warn", "info", "debug"] [default: "info"] -m, --mqtt mqtt broker url. See https://github.com/svrooij/node-xiaomi2mqtt#mqtt-url [default: "mqtt://127.0.0.1"] + -k, --insecure accept self singed-certificates when using TLS. See https://github.com/mqttjs/MQTT.js#mqttclientstreambuilder-options + [boolean] [default: false] -n, --name instance name. used as mqtt client id and as topic prefix [default: "xiaomi"] --version Show version number diff --git a/src/bridge.js b/src/bridge.js index 30c4a90..a930f49 100644 --- a/src/bridge.js +++ b/src/bridge.js @@ -33,7 +33,8 @@ function start () { message: 0, qos: 0, retain: true - } + }, + rejectUnauthorized = !config.insecure } mqttClient = mqtt.connect(config.mqtt, mqttOptions) diff --git a/src/config.js b/src/config.js index 9e437ef..b5be63b 100644 --- a/src/config.js +++ b/src/config.js @@ -4,24 +4,30 @@ const config = require('yargs') .describe('d', 'File location of device list (must end with .json).') .describe('g', 'Gateway password (to enable gateway light change)') .describe('h', 'Show this help') - .describe('l', 'possiblevalues: "error", "warn","info","debug"') + .describe('l', 'Logging level') .describe('m', 'mqtt broker url. See https://github.com/mqttjs/MQTT.js#connect-using-a-url') + .describe('k', 'accept self singed-certificates when using TLS. See https://github.com/mqttjs/MQTT.js#mqttclientstreambuilder-options') .describe('n', 'instance name. used as mqtt client id and as topic prefix') + .boolean('k') .alias({ d: 'devices', g: 'password', h: 'help', l: 'logging', m: 'mqtt', + k: 'insecure', n: 'name' }) + .choices('l', ['error', 'warn', 'info', 'debug']) .default({ l: 'info', m: 'mqtt://127.0.0.1', + k: false, n: 'xiaomi' }) .version() .help('help') + .wrap(null) .argv module.exports = config