'triton --accept-version VER ...' developer option

This commit is contained in:
Trent Mick 2015-11-25 11:04:44 -08:00
parent 48b6be58f4
commit 3cd4b0d735
3 changed files with 44 additions and 8 deletions

View File

@ -2,7 +2,13 @@
## 3.1.1 (not yet released)
(nothing yet)
- `triton --accept-version VER` hidden top-level option for development. This
allows calling the target cloudapi with the given value for the
"Accept-Version" header -- which is how CloudAPI does API versioning.
By default `triton` is coded to a particular cloudapi version range, so
forcing a different version *could* result in breaking in the triton client
code that handles the response. IOW, this is just a tool for developers
of this Triton client and CloudAPI itself.
## 3.1.0

View File

@ -104,7 +104,7 @@ var OPTIONS = [
type: 'string',
help: 'SSH key fingerprint. Environment: TRITON_KEY_ID=FINGERPRINT ' +
'or SDC_KEY_ID=FINGERPRINT.',
helpArg: 'FINGERPRINT'
helpArg: 'FP'
},
{
names: ['url', 'U'],
@ -127,6 +127,18 @@ var OPTIONS = [
'TRITON_TLS_INSECURE=1, SDC_TLS_INSECURE=1 (or the deprecated ' +
'SDC_TESTING=1).',
'default': false
},
{
names: ['accept-version'],
type: 'string',
helpArg: 'VER',
help: 'A cloudapi API version, or semver range, to attempt to use. ' +
'This is passed in the "Accept-Version" header. ' +
'See `triton cloudapi /--ping` to list supported versions. ' +
'The default is "' + tritonapi.CLOUDAPI_ACCEPT_VERSION + '". ' +
'*This is intended for development use only. It could cause ' +
'`triton` processing of responses to break.*',
hidden: true
}
];
@ -253,13 +265,20 @@ CLI.prototype.init = function (opts, args, callback) {
CLI.prototype._applyProfileOverrides =
function _applyProfileOverrides(profile) {
var self = this;
['account', 'user', 'url', 'keyId', 'insecure'].forEach(function (field) {
[
{oname: 'account', pname: 'account'},
{oname: 'user', pname: 'user'},
{oname: 'url', pname: 'url'},
{oname: 'keyId', pname: 'keyId'},
{oname: 'insecure', pname: 'insecure'},
{oname: 'accept_version', pname: 'acceptVersion'}
].forEach(function (field) {
// We need to check `opts._order` to know if boolean opts
// were specified.
var specified = self.opts._order.filter(
function (opt) { return opt.key === field; }).length > 0;
function (opt) { return opt.key === field.oname; }).length > 0;
if (specified) {
profile[field] = self.opts[field];
profile[field.pname] = self.opts[field.oname];
}
});
};

View File

@ -31,6 +31,11 @@ var errors = require('./errors');
var loadConfigSync = require('./config').loadConfigSync;
// ---- globals
var CLOUDAPI_ACCEPT_VERSION = '~8||~7';
// ---- internal support stuff
@ -117,8 +122,11 @@ TritonApi.prototype._cloudapiFromProfile =
assert.optionalString(profile.user, 'profile.user');
assert.optionalString(profile.privKey, 'profile.privKey');
assert.optionalBool(profile.insecure, 'profile.insecure');
assert.optionalString(profile.acceptVersion, 'profile.acceptVersion');
var rejectUnauthorized = (profile.insecure === undefined
? true : !profile.insecure);
var acceptVersion = profile.acceptVersion || CLOUDAPI_ACCEPT_VERSION;
var sign;
if (profile.privKey) {
@ -139,7 +147,7 @@ TritonApi.prototype._cloudapiFromProfile =
url: profile.url,
account: profile.account,
user: profile.user,
version: '*',
version: acceptVersion,
rejectUnauthorized: rejectUnauthorized,
sign: sign,
log: this.log
@ -933,6 +941,9 @@ TritonApi.prototype.deletePolicy = function deletePolicy(opts, cb) {
//---- exports
module.exports.createClient = function (options) {
return new TritonApi(options);
module.exports = {
CLOUDAPI_ACCEPT_VERSION: CLOUDAPI_ACCEPT_VERSION,
createClient: function createClient(opts) {
return new TritonApi(opts);
}
};