From 68e5b685832293bff25c888733c963dbcbe9ed6e Mon Sep 17 00:00:00 2001 From: Chris Burroughs Date: Tue, 24 Jan 2017 10:19:48 -0500 Subject: [PATCH] PUBAPI-1171 improve boolean envvar error handling PUBAPI-1205 mirror node-smartdc meaning for SDC_TESTING PUBAPI-1351 label each group of env vars for clarity Reviewed by: Trent Mick Approved by: Trent Mick --- CHANGES.md | 9 +++++++++ lib/config.js | 11 ++++++----- lib/do_env.js | 10 +++++++--- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 494f340..fa473a7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,15 @@ Known issues: ## not yet released +- PUBAPI-1171/PUBAPI-1205/PUBAPI-1351 The handling of legacy `SDC_*` + environment variables has been cleaned up. These environment + variables are used for compatibility with the node-smartdc toolset. + * `SDC_TESTING` is now evaluated the same way as node-smartdc. Any + set value but the empty string is true. + * Errors on boolean environment variables will now identify the + variable at fault. + * `triton env` will emit additional comments grouping variables. + - [joyent/node-triton#80] Add `triton network list public=true|false` filtering. Note that this filtering is client-side. diff --git a/lib/config.js b/lib/config.js index 10f22c2..175858a 100644 --- a/lib/config.js +++ b/lib/config.js @@ -288,15 +288,16 @@ function _loadEnvProfile() { { return null; } - if (process.env.TRITON_TLS_INSECURE) { envProfile.insecure = common.boolFromString( - process.env.TRITON_TLS_INSECURE); + process.env.TRITON_TLS_INSECURE, undefined, 'TRITON_TLS_INSECURE'); } else if (process.env.SDC_TLS_INSECURE) { envProfile.insecure = common.boolFromString( - process.env.SDC_TLS_INSECURE); - } else if (process.env.SDC_TESTING) { // deprecated - envProfile.insecure = common.boolFromString(process.env.SDC_TESTING); + process.env.SDC_TLS_INSECURE, undefined, 'SDC_TLS_INSECURE'); + } else if (process.env.SDC_TESTING) { + // For compatibility with the legacy behavior of the smartdc + // tools, *any* set value but the empty string is considered true. + envProfile.insecure = true; } validateProfile(envProfile, 'environment variables'); diff --git a/lib/do_env.js b/lib/do_env.js index 9653879..f6ba08e 100644 --- a/lib/do_env.js +++ b/lib/do_env.js @@ -71,6 +71,7 @@ function do_env(subcmd, opts, args, cb) { clientTypes.forEach(function (clientType) { switch (clientType) { case 'triton': + p('# triton'); if (opts.unset) { [ 'TRITON_PROFILE', @@ -87,6 +88,7 @@ function do_env(subcmd, opts, args, cb) { } break; case 'docker': + p('# docker'); var setupJson = path.resolve(self.configDir, 'docker', common.profileSlug(profile), 'setup.json'); if (fs.existsSync(setupJson)) { @@ -124,6 +126,7 @@ function do_env(subcmd, opts, args, cb) { } break; case 'smartdc': + p('# smartdc'); if (opts.unset) { [ 'SDC_URL', @@ -186,7 +189,8 @@ do_env.options = [ { names: ['smartdc', 's'], type: 'bool', - help: 'Emit environment for node-smartdc (i.e. the "SDC_*" variables).' + help: 'Emit environment for node-smartdc (i.e. the legacy ' + + '"SDC_*" variables).' }, { group: '' @@ -211,8 +215,8 @@ do_env.help = [ '{{usage}}', '', '{{options}}', - 'If no options are given, environment variables are emitted for all clients.', - 'If PROFILE is not given, the current profile is used.', + 'If no options are given, environment variables are emitted for all ', + 'clients. If PROFILE is not given, the current profile is used.', '', 'The following Bash function can be added to one\'s "~/.bashrc" to quickly', 'change between Triton profiles:',