Skip to content

Commit 43d01f6

Browse files
committed
Add TLS-Support from breser#154
1 parent f2052fd commit 43d01f6

File tree

7 files changed

+51
-4
lines changed

7 files changed

+51
-4
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ There are environment variable equivalents for the parameters that git2consul ac
148148
* `CONSUL_ENDPOINT` maps to `-e` or `--endpoint`
149149
* `CONSUL_PORT` maps to `-p` or `--port`
150150
* `CONSUL_SECURE` maps to `-s` or `--secure`
151+
* `CONSUL_CERT` maps to `--cert`
152+
* `CONSUL_KEY` maps to `--key`
153+
* `CONSUL_CA` maps to `--ca`
151154
* `TOKEN` maps to `-t` or `--token`
152155

153156

lib/config_reader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var consul = require('consul')({'host': global.endpoint, 'port': global.port, 'secure':global.secure});
1+
var consul = require('consul')({'host': global.endpoint, 'port': global.port, 'secure':global.secure, 'cert': global.cert, 'key': global.key, 'ca': global.ca});
22

33
var _ = require('underscore');
44

lib/config_seeder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var fs = require('fs');
22
var _ = require('underscore');
33

4-
var consul = require('consul')({'host': global.endpoint, 'port': global.port, 'secure': global.secure});
4+
var consul = require('consul')({'host': global.endpoint, 'port': global.port, 'secure': global.secure, 'cert': global.cert, 'key': global.key, 'ca': global.ca});
55
var logger = require('./logging.js');
66

77
/**

lib/consul/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var utils = require('../utils.js');
66

77
var logger = require('../logging.js');
88

9-
var consul = require('consul')({'host': global.endpoint, 'port': global.port, 'secure': global.secure});
9+
var consul = require('consul')({'host': global.endpoint, 'port': global.port, 'secure': global.secure, 'cert': global.cert, 'key': global.key, 'ca': global.ca});
1010

1111
var token = undefined;
1212

lib/index.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ var os = require('os');
1010
global.endpoint = process.env.CONSUL_ENDPOINT || "127.0.0.1";
1111
global.port = process.env.CONSUL_PORT || 8500;
1212
global.secure = process.env.CONSUL_SECURE || false;
13+
global.cert_filename = process.env.CONSUL_CERT || '';
14+
global.key_filename = process.env.CONSUL_KEY || '';
15+
global.ca_filename = process.env.CONSUL_CA || '';
1316
global.token = process.env.TOKEN || null;
1417
global.config_file = null;
1518
global.config_key = "git2consul/config"
@@ -60,7 +63,45 @@ for (var i=2; i<process.argv.length; ++i) {
6063
}
6164
global.config_file = process.argv[i+1];
6265
}
66+
67+
if(process.argv[i] === '--cert') {
68+
if(i+1 >= process.argv.length) {
69+
logger.error("No file provided with --cert option");
70+
process.exit(7);
71+
}
72+
global.cert_filename = process.argv[i+1];
73+
}
74+
75+
if(process.argv[i] === '--key') {
76+
if(i+1 >= process.argv.length) {
77+
logger.error("No file provided with --key option");
78+
process.exit(7);
79+
}
80+
global.key_filename = process.argv[i+1];
81+
}
82+
83+
if(process.argv[i] === '--ca') {
84+
if(i+1 >= process.argv.length) {
85+
logger.error("No file provided with --ca option");
86+
process.exit(7);
87+
}
88+
global.ca_filename = process.argv[i+1];
89+
}
90+
}
91+
92+
/**
93+
* Read the certificate, key and CA files.
94+
*/
95+
if (global.cert_filename !== '') {
96+
global.cert = fs.readFileSync(global.cert_filename);
97+
}
98+
if (global.key_filename !== '') {
99+
global.key = fs.readFileSync(global.key_filename);
63100
}
101+
if (global.ca_filename !== '') {
102+
global.ca = fs.readFileSync(global.ca_filename);
103+
}
104+
64105

65106
var config_reader = require('./config_reader.js');
66107
var config_seeder = require('./config_seeder.js');

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"dependencies": {
1717
"body-parser": "~1.4.3",
1818
"bunyan": "1.1.3",
19-
"consul": "^0.10.0",
19+
"consul": "^0.29.0",
2020
"coveralls": "^2.11.2",
2121
"express": "~4.6.1",
2222
"mkdirp": "0.5.0",

utils/config_seeder.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ var logger = require('../lib/logging.js');
1010
global.endpoint = process.env.CONSUL_ENDPOINT || "127.0.0.1";
1111
global.port = process.env.CONSUL_PORT || 8500;
1212
global.secure = process.env.CONSUL_SECURE || false;
13+
global.cert_filename = process.env.CONSUL_CERT || '';
14+
global.key_filename = process.env.CONSUL_KEY || '';
15+
global.ca_filename = process.env.CONSUL_CA || '';
1316
global.token = process.env.TOKEN || null;
1417
global.config_key = "git2consul/config";
1518

0 commit comments

Comments
 (0)