From 01070bcf6cf72f32e80fdf0094fb4f1fc1bdbb37 Mon Sep 17 00:00:00 2001 From: Simo Kinnunen Date: Thu, 30 Jan 2014 00:58:03 +0900 Subject: [PATCH] Simplify environment variable overrides. --- lib/cli.js | 78 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 38 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 5726c30c..22b34df8 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -147,56 +147,60 @@ program .option('-p, --port ' , 'port (or $PORT)' , Number - , 7120) + , process.env.PORT || 7120) .option('-s, --secret ' , 'secret (or $SECRET)' - , String) + , String + , process.env.SECRET) .option('-i, --ssid ' , 'session SSID (or $SSID)' , String - , 'ssid') + , process.env.SSID || 'ssid') .option('-u, --ldap-url ' , 'LDAP server URL (or $LDAP_URL)' - , String) + , String + , process.env.LDAP_URL) .option('-t, --ldap-timeout ' , 'LDAP timeout (or $LDAP_TIMEOUT)' , Number - , 1000) + , process.env.LDAP_TIMEOUT || 1000) .option('--ldap-bind-dn ' , 'LDAP bind DN (or $LDAP_BIND_DN)' - , String) + , String + , process.env.LDAP_BIND_DN) .option('--ldap-bind-credentials ' , 'LDAP bind credentials (or $LDAP_BIND_CREDENTIALS)' - , String) + , String + , process.env.LDAP_BIND_CREDENTIALS) .option('--ldap-search-dn ' , 'LDAP search DN (or $LDAP_SEARCH_DN)' - , String) + , String + , process.env.LDAP_SEARCH_DN) .option('--ldap-search-scope ' , 'LDAP search scope (or $LDAP_SEARCH_SCOPE)' , String - , 'sub') + , process.env.LDAP_SEARCH_SCOPE || 'sub') .option('--ldap-search-class ' , 'LDAP search objectClass (or $LDAP_SEARCH_CLASS)' , String - , 'user') + , process.env.LDAP_SEARCH_CLASS || 'user') .action(function(options) { - var env = process.env require('./roles/auth/ldap')({ - port: env.PORT || options.port - , secret: options.secret || env.SECRET - , ssid: options.ssid || env.SSID + port: options.port + , secret: options.secret + , ssid: options.ssid , ldap: { - url: options.ldapUrl || env.LDAP_URL - , timeout: options.ldapTimeout || env.LDAP_TIMEOUT + url: options.ldapUrl + , timeout: options.ldapTimeout , bind: { - dn: options.ldapBindDn || env.LDAP_BIND_DN - , credentials: options.ldapBindCredentials || env.LDAP_BIND_CREDENTIALS + dn: options.ldapBindDn + , credentials: options.ldapBindCredentials } , search: { - dn: options.ldapSearchDn || env.LDAP_SEARCH_DN - , scope: options.ldapSearchScope || env.LDAP_SEARCH_SCOPE - , objectClass: options.ldapSearchClass || env.LDAP_SEARCH_CLASS - , loginField: options.ldapSearchLoginField || env.LDAP_SEARCH_LOGINFIELD + dn: options.ldapSearchDn + , scope: options.ldapSearchScope + , objectClass: options.ldapSearchClass + , loginField: options.ldapSearchLoginField } } }) @@ -208,20 +212,19 @@ program .option('-p, --port ' , 'port (or $PORT)' , Number - , 7120) + , process.env.PORT || 7120) .option('-s, --secret ' , 'secret (or $SECRET)' - , String) + , String + , process.env.SECRET) .option('-i, --ssid ' , 'session SSID (or $SSID)' , String - , 'ssid') + , process.env.SSID || 'ssid') .option('-a, --app-url ' , 'URL to app' , String) .action(function(options) { - var env = process.env - if (!options.secret) { this.missingArgument('--secret') } @@ -230,9 +233,9 @@ program } require('./roles/auth/mock')({ - port: env.PORT || options.port - , secret: options.secret || env.SECRET - , ssid: options.ssid || env.SSID + port: options.port + , secret: options.secret + , ssid: options.ssid , appUrl: options.appUrl }) }) @@ -282,20 +285,19 @@ program .option('-p, --port ' , 'port (or $PORT)' , Number - , 7100) + , process.env.PORT || 7100) .option('-s, --secret ' , 'secret (or $SECRET)' - , String) + , String + , process.env.SECRET) .option('-i, --ssid ' , 'session SSID (or $SSID)' , String - , 'ssid') + , process.env.SSID || 'ssid') .option('-a, --auth-url ' , 'URL to auth client' , String) .action(function(options) { - var env = process.env - if (!options.secret) { this.missingArgument('--secret') } @@ -304,9 +306,9 @@ program } require('./roles/app')({ - port: env.PORT || options.port - , secret: options.secret || env.SECRET - , ssid: options.ssid || env.SSID + port: options.port + , secret: options.secret + , ssid: options.ssid , authUrl: options.authUrl }) })