joyent/node-triton#156 allow all profile fields to be given on the cli
Reviewed by: Trent Mick <trent.mick@joyent.com> Approved by: Trent Mick <trent.mick@joyent.com>
This commit is contained in:
parent
68e5b68583
commit
75cb032f3a
@ -7,6 +7,10 @@ Known issues:
|
|||||||
|
|
||||||
## not yet released
|
## not yet released
|
||||||
|
|
||||||
|
- [joyent/node-triton#156] Providing all required profile options as
|
||||||
|
command line flags (account, url, keyId) no longer produces an
|
||||||
|
incomplete profile error.
|
||||||
|
|
||||||
- PUBAPI-1171/PUBAPI-1205/PUBAPI-1351 The handling of legacy `SDC_*`
|
- PUBAPI-1171/PUBAPI-1205/PUBAPI-1351 The handling of legacy `SDC_*`
|
||||||
environment variables has been cleaned up. These environment
|
environment variables has been cleaned up. These environment
|
||||||
variables are used for compatibility with the node-smartdc toolset.
|
variables are used for compatibility with the node-smartdc toolset.
|
||||||
|
21
lib/cli.js
21
lib/cli.js
@ -282,7 +282,8 @@ CLI.prototype.init = function (opts, args, callback) {
|
|||||||
try {
|
try {
|
||||||
self._profile = mod_config.loadProfile({
|
self._profile = mod_config.loadProfile({
|
||||||
configDir: self.configDir,
|
configDir: self.configDir,
|
||||||
name: self.profileName
|
name: self.profileName,
|
||||||
|
profileOverrides: self._cliOptsAsProfile()
|
||||||
});
|
});
|
||||||
} catch (pErr) {
|
} catch (pErr) {
|
||||||
/*
|
/*
|
||||||
@ -304,7 +305,6 @@ CLI.prototype.init = function (opts, args, callback) {
|
|||||||
}
|
}
|
||||||
throw pErr;
|
throw pErr;
|
||||||
}
|
}
|
||||||
self._applyProfileOverrides(self._profile);
|
|
||||||
self.log.trace({profile: self._profile}, 'loaded profile');
|
self.log.trace({profile: self._profile}, 'loaded profile');
|
||||||
}
|
}
|
||||||
return self._profile;
|
return self._profile;
|
||||||
@ -578,8 +578,22 @@ CLI.prototype._emitCompletions = function _emitCompletions(type, cb) {
|
|||||||
* Apply overrides from CLI options to the given profile object *in place*.
|
* Apply overrides from CLI options to the given profile object *in place*.
|
||||||
*/
|
*/
|
||||||
CLI.prototype._applyProfileOverrides =
|
CLI.prototype._applyProfileOverrides =
|
||||||
function _applyProfileOverrides(profile) {
|
function _applyProfileOverrides(profile) {
|
||||||
|
var optProfile = this._cliOptsAsProfile();
|
||||||
|
for (var attr in optProfile) {
|
||||||
|
profile[attr] = optProfile[attr];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create a profile dict from any cli override options specified.
|
||||||
|
* Unless all profile flags are specified on the cli, this profile
|
||||||
|
* will be incomplete and will need to be combined with another
|
||||||
|
* configuration source.
|
||||||
|
*/
|
||||||
|
CLI.prototype._cliOptsAsProfile = function _cliOptsAsProfile() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
var profile = {};
|
||||||
[
|
[
|
||||||
{oname: 'account', pname: 'account'},
|
{oname: 'account', pname: 'account'},
|
||||||
{oname: 'user', pname: 'user'},
|
{oname: 'user', pname: 'user'},
|
||||||
@ -598,6 +612,7 @@ CLI.prototype._applyProfileOverrides =
|
|||||||
profile[field.pname] = self.opts[field.oname];
|
profile[field.pname] = self.opts[field.oname];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return profile;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -267,7 +267,7 @@ function validateProfile(profile, profilePath) {
|
|||||||
* @throws {errors.ConfigError} If the profile defined by the environment is
|
* @throws {errors.ConfigError} If the profile defined by the environment is
|
||||||
* invalid.
|
* invalid.
|
||||||
*/
|
*/
|
||||||
function _loadEnvProfile() {
|
function _loadEnvProfile(profileOverrides) {
|
||||||
var envProfile = {
|
var envProfile = {
|
||||||
name: 'env'
|
name: 'env'
|
||||||
};
|
};
|
||||||
@ -280,14 +280,6 @@ function _loadEnvProfile() {
|
|||||||
envProfile.url = process.env.TRITON_URL || process.env.SDC_URL;
|
envProfile.url = process.env.TRITON_URL || process.env.SDC_URL;
|
||||||
envProfile.keyId = process.env.TRITON_KEY_ID || process.env.SDC_KEY_ID;
|
envProfile.keyId = process.env.TRITON_KEY_ID || process.env.SDC_KEY_ID;
|
||||||
|
|
||||||
/*
|
|
||||||
* If none of the above envvars are defined, then there is no env profile.
|
|
||||||
*/
|
|
||||||
if (!envProfile.account && !envProfile.user && !envProfile.url &&
|
|
||||||
!envProfile.keyId)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (process.env.TRITON_TLS_INSECURE) {
|
if (process.env.TRITON_TLS_INSECURE) {
|
||||||
envProfile.insecure = common.boolFromString(
|
envProfile.insecure = common.boolFromString(
|
||||||
process.env.TRITON_TLS_INSECURE, undefined, 'TRITON_TLS_INSECURE');
|
process.env.TRITON_TLS_INSECURE, undefined, 'TRITON_TLS_INSECURE');
|
||||||
@ -300,12 +292,23 @@ function _loadEnvProfile() {
|
|||||||
envProfile.insecure = true;
|
envProfile.insecure = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (var attr in profileOverrides) {
|
||||||
|
envProfile[attr] = profileOverrides[attr];
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* If none of the above envvars are defined, then there is no env profile.
|
||||||
|
*/
|
||||||
|
if (!envProfile.account && !envProfile.user && !envProfile.url &&
|
||||||
|
!envProfile.keyId)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
validateProfile(envProfile, 'environment variables');
|
validateProfile(envProfile, 'environment variables');
|
||||||
|
|
||||||
return envProfile;
|
return envProfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _profileFromPath(profilePath, name) {
|
function _profileFromPath(profilePath, name, profileOverrides) {
|
||||||
if (! fs.existsSync(profilePath)) {
|
if (! fs.existsSync(profilePath)) {
|
||||||
throw new errors.ConfigError('no such profile: ' + name);
|
throw new errors.ConfigError('no such profile: ' + name);
|
||||||
}
|
}
|
||||||
@ -324,6 +327,9 @@ function _profileFromPath(profilePath, name) {
|
|||||||
}
|
}
|
||||||
profile.name = name;
|
profile.name = name;
|
||||||
|
|
||||||
|
for (var attr in profileOverrides) {
|
||||||
|
profile[attr] = profileOverrides[attr];
|
||||||
|
}
|
||||||
validateProfile(profile, profilePath);
|
validateProfile(profile, profilePath);
|
||||||
|
|
||||||
return profile;
|
return profile;
|
||||||
@ -333,9 +339,10 @@ function _profileFromPath(profilePath, name) {
|
|||||||
function loadProfile(opts) {
|
function loadProfile(opts) {
|
||||||
assert.string(opts.name, 'opts.name');
|
assert.string(opts.name, 'opts.name');
|
||||||
assert.optionalString(opts.configDir, 'opts.configDir');
|
assert.optionalString(opts.configDir, 'opts.configDir');
|
||||||
|
assert.optionalObject(opts.profileOverrides, 'opts.profileOverrides');
|
||||||
|
|
||||||
if (opts.name === 'env') {
|
if (opts.name === 'env') {
|
||||||
var envProfile = _loadEnvProfile();
|
var envProfile = _loadEnvProfile(opts.profileOverrides);
|
||||||
if (!envProfile) {
|
if (!envProfile) {
|
||||||
throw new errors.ConfigError('could not load "env" profile '
|
throw new errors.ConfigError('could not load "env" profile '
|
||||||
+ '(missing TRITON_*, or SDC_*, environment variables)');
|
+ '(missing TRITON_*, or SDC_*, environment variables)');
|
||||||
@ -348,7 +355,7 @@ function loadProfile(opts) {
|
|||||||
var profilePath = path.resolve(
|
var profilePath = path.resolve(
|
||||||
common.tildeSync(opts.configDir), 'profiles.d',
|
common.tildeSync(opts.configDir), 'profiles.d',
|
||||||
opts.name + '.json');
|
opts.name + '.json');
|
||||||
return _profileFromPath(profilePath, opts.name);
|
return _profileFromPath(profilePath, opts.name, opts.profileOverrides);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user