diff options
Diffstat (limited to 'lib/config.js')
-rw-r--r-- | lib/config.js | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/lib/config.js b/lib/config.js index fd7d38c..8daa87f 100644 --- a/lib/config.js +++ b/lib/config.js @@ -52,10 +52,12 @@ See the License for the specific language governing permissions and limitations * Basic authentication and supply "admin" as a user name with "admin123" as the password or * supply "other" as the user name with "other123" as the password. * - * The dispatcher will attempt to run using TLS (i.e., as an HTTPS server) if a certificate - * file in pkcs12 format is stored at etc/cert/cert and a file containing the corresponding - * passphrase is stored at etc/cert/pass. These files can be made available to the container - * running the dispatcher by mounting a volume to the container. + * The deployment-handler will attempt to run its web-server using TLS (i.e., as an HTTPS server) + * if a certificate file in pkcs12 format is stored at etc/cert/cert and a file containing the + * corresponding passphrase is stored at etc/cert/pass. + * - alternative files can be at etc/cert/cert.p12 and etc/cert/p12.pass, respectively. + * These files can be made available to the container running the deployment-handler by + * mounting a volume to the container. */ "use strict"; @@ -65,6 +67,9 @@ const consul = require("./consul"); const SSL_CERT_FILE = "etc/cert/cert"; const SSL_PASS_FILE = "etc/cert/pass"; +const SSL_CERT_P12_FILE = "etc/cert/cert.p12"; +const SSL_P12_PASS_FILE = "etc/cert/p12.pass"; + const PACKAGE_JSON_FILE = "./package.json"; const CONFIG_KEY = "deployment_handler"; /* Configuration is stored under the name "deployment_handler" */ @@ -120,21 +125,21 @@ const getFileContents = function(path) { else { resolve(data); } - }) - }) + }); + }); }; /* Check for a TLS cert file and passphrase */ -const getTLSCredentials = function() { - var ssl = {}; +const getTLSCredentials = function(ssl_pass_file, ssl_cert_file) { + const ssl = {}; /* Get the passphrase */ - return getFileContents(SSL_PASS_FILE) + return getFileContents(ssl_pass_file) .then(function(phrase) { ssl.passphrase = phrase.toString('utf8').trim(); /* Get the cert */ - return getFileContents(SSL_CERT_FILE); + return getFileContents(ssl_cert_file); }) .then(function(cert) { @@ -143,9 +148,10 @@ const getTLSCredentials = function() { }) .catch(function(err) { - return {}; + console.log((new Date()) + ": getTLSCredentials", err.toString()); + return; }); -} +}; exports.configure = function() { const config = {}; @@ -202,11 +208,17 @@ exports.configure = function() { .then(function(invService) { config.inventory.url = config.inventory.protocol + "://" + invService.address + ":" + invService.port + INV_API_PATH; - /* Get TLS credentials, if they exist */ - return getTLSCredentials(); + console.log((new Date()) + ": looking for tls files", SSL_PASS_FILE, SSL_CERT_FILE); + return getTLSCredentials(SSL_PASS_FILE, SSL_CERT_FILE); + }) + .then(function(tls) { + if (tls) {return tls;} + + console.log((new Date()) + ": looking for alternative tls files", SSL_P12_PASS_FILE, SSL_CERT_P12_FILE); + return getTLSCredentials(SSL_P12_PASS_FILE, SSL_CERT_P12_FILE); }) .then(function(tls) { - config.ssl = tls; + if (tls) {config.ssl = tls;} /* Check for missing required configuration parameters */ const missing = findMissingConfig(config); @@ -214,7 +226,7 @@ exports.configure = function() { throw new Error ("Required configuration elements missing: " + missing.join(',')); config = null; } - console.log( (new Date()) + ": config -> " + JSON.stringify(config, undefined, 2)); + console.log((new Date()) + ": config -> " + JSON.stringify(config, utils.hideSecrets, 2)); return config; }); }; |