forked from LeisureLink/consul-kv-sync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
consul-kv-sync.js
executable file
·56 lines (51 loc) · 2.02 KB
/
consul-kv-sync.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env node
'use strict';
const program = require('commander');
const pkg = require('./package');
const log = require('./lib/logger');
const clientFactory = require('./lib/client');
const workflowFactory = require('./lib/workflow');
function collectCA(value, items) {
items.push(value);
}
program.version(pkg.version)
.usage('[options] <file ...>')
.description('Synchronizes one or more JSON manifests with consul\'s key value store.')
.option('-H, --host <host>', 'Consul API url. Environment variable: CONSUL_HOST. Default: consul.service.consul')
.option('-p, --port <port>', 'Consul API port. Environment variable: CONSUL_PORT. Default: 8500')
.option('-s, --secure', 'Enable HTTPS. Environment variable: CONSUL_SECURE.')
.option('--ca <ca>', 'Path to trusted certificate in PEM format. Specify multiple times for multiple certificates.', collectCA, [])
.option('-v, --verbose', 'If present, verbose output provided.')
.on('--help', function() {
console.log(' Examples:');
console.log('');
console.log(' $ consul-kv-sync my-service-global.json my-service-dev.json');
console.log(' $ CONSUL_HOST=consul.local consul-kv-sync my-service-global.json my-service-dev.json');
console.log(' $ consul-kv-sync --host localhost --port 8500 --secure \\');
console.log(' --ca root-ca.pem --ca intermediate-ca.pem \\');
console.log(' my-service-global.json my-service-dev.json');
console.log('');
});
program.parse(process.argv);
if (!program.args.length) {
program.outputHelp();
process.exit(1);
}
if (program.verbose) {
log.transports.console.level = 'debug';
}
let client = clientFactory(program);
let workflow = workflowFactory(client, program.args);
workflow.exec().then(() => {
log.info('Sync completed. ' + workflow.stats.put + ' items set, ' + workflow.stats.deleted + ' items deleted.');
log.info('Config:');
log.info(workflow.config);
})
.catch((err) => {
if (program.verbose) {
log.error(err);
} else {
log.error(err.message);
}
process.exit(99);
});