From b238fcf52fcf3bb8460d998cf9dd89af11f93f7b Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Wed, 23 Sep 2015 21:08:26 -0700 Subject: [PATCH] improve on a DEPTH_ZERO_SELF_SIGNED_CERT error from: triton account: error: DEPTH_ZERO_SELF_SIGNED_CERT to this: triton account: error (SelfSignedCert): could not access CloudAPI https://10.88.88.3 because it uses a self-signed TLS certificate and your current profile is not configured for insecure access: DEPTH_ZERO_SELF_SIGNED_CERT --- lib/cli.js | 2 +- lib/cloudapi2.js | 16 ++++++++++++++++ lib/errors.js | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/cli.js b/lib/cli.js index 87a9814..6c52cc4 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -309,7 +309,7 @@ function main(argv) { var showErr = (cli.showErr !== undefined ? cli.showErr : true); if (err && showErr) { - var code = (err.body ? err.body.code : err.code); + var code = (err.body ? err.body.code : err.code) || err.restCode; if (code === 'NoCommand') { /* jsl:pass */ } else if (err.message !== undefined) { diff --git a/lib/cloudapi2.js b/lib/cloudapi2.js index d83e61b..1638cc0 100644 --- a/lib/cloudapi2.js +++ b/lib/cloudapi2.js @@ -247,6 +247,7 @@ CloudApi.prototype._request = function _request(options, callback) { */ CloudApi.prototype._passThrough = function _passThrough(endpoint, opts, cb) { + var self = this; if (typeof (opts) === 'function') { cb = opts; opts = null; @@ -259,6 +260,21 @@ function _passThrough(endpoint, opts, cb) { var p = this._path(endpoint, opts); this._request(p, function (err, req, res, body) { + /* + * Improve this kind of error message: + * + * Error: DEPTH_ZERO_SELF_SIGNED_CERT + * at SecurePair. (tls.js:1381:32) + * at SecurePair.emit (events.js:92:17) + * + * TODO: could generalize this into a wrapErr method. + */ + if (err && err.message === 'DEPTH_ZERO_SELF_SIGNED_CERT' && + self.client.rejectUnauthorized) + { + err = new errors.SelfSignedCertError(err, self.url); + } + cb(err, body, res); }); }; diff --git a/lib/errors.js b/lib/errors.js index cceab7d..d578be1 100644 --- a/lib/errors.js +++ b/lib/errors.js @@ -113,6 +113,23 @@ function SigningError(cause) { util.inherits(SigningError, TritonError); +/** + * A 'DEPTH_ZERO_SELF_SIGNED_CERT' An error signing a request. + */ +function SelfSignedCertError(cause, url) { + var msg = format('could not access CloudAPI %s because it uses a ' + + 'self-signed TLS certificate and your current profile is not ' + + 'configured for insecure access', url); + TritonError.call(this, { + cause: cause, + message: msg, + code: 'SelfSignedCert', + exitStatus: 1 + }); +} +util.inherits(SelfSignedCertError, TritonError); + + /** * Multiple errors in a group. */ @@ -143,6 +160,7 @@ module.exports = { ConfigError: ConfigError, UsageError: UsageError, SigningError: SigningError, + SelfSignedCertError: SelfSignedCertError, MultiError: MultiError }; // vim: set softtabstop=4 shiftwidth=4: