From 4a46310a8ddc21d0a833b5895151ba5fa719a123 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Tue, 24 Nov 2015 16:40:17 -0800 Subject: [PATCH] experimental 'triton env [PROFILE]' --- CHANGES.md | 17 +++++++- lib/cli.js | 1 + lib/do_env.js | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 4 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 lib/do_env.js diff --git a/CHANGES.md b/CHANGES.md index 271bbf5..7709b0b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,12 +1,24 @@ # node-triton changelog -## 3.0.1 (not yet released) +## 3.1.0 (not yet released) + +- New (hidden for now, i.e. experimental) `triton env ...` to dump + `eval`able shell commands for + [node-smartdc](https://github.com/joyent/node-smartdc) environment setup for + a given Triton CLI profile. E.g.: + + eval $(triton env east1) + sdc-listmachines + + I think this should grow to support setting up Docker env as well. - #54 `triton rbac role-tags` for now can't be hidden (as long we have the need to role-tag raw resource URLs like '/my/images'). + - #54 `triton rbac apply --dev-create-keys-and-profiles` for experimenting/dev/testing to quickly generate and add user keys and setup Triton CLI profiles for all users in the RBAC config. + - #54 RBAC support, see to start. - `triton rbac info` improvements: better help, use brackets to show non-default roles. @@ -14,11 +26,14 @@ - change `triton rbac user USER` output a little for the 'keys' (show the key fingerprint and name instead of the key content), 'roles', and 'default_roles' fields. + - #54 *Drop* support for shortIds for `triton rbac {users,roles,policies}` commands. They all have unique *`name`* fields, just use that. + - #54 `triton rbac apply` will implicitly look for a user key file at "./rbac-user-keys/$login.pub" if no `keys` field is provided in the "rbac.json" config file. + - Change default `triton keys` and `triton rbac keys` output to be tabular. Otherwise it is a little obtuse to see fingerprints (which is what currently must be included in a profile). `triton [rbac] keys -A` can be used to diff --git a/lib/cli.js b/lib/cli.js index c381d28..c04e0ac 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -269,6 +269,7 @@ CLI.prototype._applyProfileOverrides = CLI.prototype.do_completion = require('./do_completion'); CLI.prototype.do_profiles = require('./do_profiles'); CLI.prototype.do_profile = require('./do_profile'); +CLI.prototype.do_env = require('./do_env'); // Other CLI.prototype.do_account = require('./do_account'); diff --git a/lib/do_env.js b/lib/do_env.js new file mode 100644 index 0000000..94ddf58 --- /dev/null +++ b/lib/do_env.js @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2015 Joyent Inc. + * + * `triton env ...` + */ + +var assert = require('assert-plus'); +var format = require('util').format; +var fs = require('fs'); +var strsplit = require('strsplit'); +var sshpk = require('sshpk'); +var tilde = require('tilde-expansion'); +var vasync = require('vasync'); + +var common = require('./common'); +var errors = require('./errors'); +var mod_config = require('./config'); + + + +function do_env(subcmd, opts, args, cb) { + if (opts.help) { + this.do_help('help', {}, [subcmd], cb); + return; + } + if (args.length > 1) { + return cb(new errors.UsageError('too many arguments')); + } + + var profileName = args[0] || this.tritonapi.profile.name; + var clientType = 'smartdc'; + if (opts.smartdc) { + clientType = 'smartdc'; + } + + try { + var profile = mod_config.loadProfile({ + configDir: this.configDir, + name: profileName + }); + } catch (err) { + return cb(err); + } + if (profile.name === this.tritonapi.profile.name) { + this._applyProfileOverrides(profile); + } + + var p = console.log; + switch (clientType) { + case 'smartdc': + p('export SDC_URL="%s"', profile.url); + p('export SDC_ACCOUNT="%s"', profile.account); + if (profile.user) { + p('export SDC_USER="%s"', profile.user); + } else { + p('unset SDC_USER'); + } + p('export SDC_KEY_ID="%s"', profile.keyId); + if (profile.insecure) { + p('export SDC_TESTING="%s"', profile.insecure); + } else { + p('unset SDC_TESTING'); + } + p('# Run this command to configure your shell:'); + p('# eval "$(triton env -s %s)"', profile.name); + break; + default: + return cb(new errors.InternalError( + 'unknown clientType: ' + clientType)); + } +} + +do_env.options = [ + { + names: ['help', 'h'], + type: 'bool', + help: 'Show this help.' + }, + { + names: ['smartdc', 's'], + type: 'bool', + help: 'Emit environment commands for node-smartdc.' + } +]; + +do_env.help = [ + /* BEGIN JSSTYLED */ + 'Emit shell environment commands to setup clients for a particular CLI profile.', + '', + 'Supported "clients" here are: node-smartdc (the `sdc-*` tools).', + 'TODO: support for `triton` and `docker`.', + '', + 'Note: By default this *currently* emits the environment for node-smartdc.', + 'However, automated usage should use `-s` to guaratee that. The default', + 'might change', + '', + 'Usage:', + ' {{name}} env [PROFILE]', + '', + '{{options}}' + /* END JSSTYLED */ +].join('\n'); + + +do_env.hidden = true; + +module.exports = do_env; diff --git a/package.json b/package.json index 2f6c25f..b46f601 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "triton", "description": "Joyent Triton CLI and client (https://www.joyent.com/triton)", - "version": "3.0.1", + "version": "3.1.0", "author": "Joyent (joyent.com)", "dependencies": { "assert-plus": "0.1.5",