From 4fba3e0bc1428175f06772c6aeac54f16ef00d5d Mon Sep 17 00:00:00 2001 From: Dmytro Medun Date: Wed, 15 Jun 2016 15:03:02 +0200 Subject: [PATCH 1/5] testcommit --- commands/import.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/commands/import.js b/commands/import.js index 38bd338..2053b9e 100644 --- a/commands/import.js +++ b/commands/import.js @@ -41,12 +41,14 @@ module.exports = Command.extend({ dashboard: {type: 'boolean', alias: 'd'}, save: {type: 'string', alias: 's'}, portal: {type: 'string', alias: 'p'} + //,verbose: {type: 'string', alias: 'v'} }), run: function () { - + this.options.verbose = true; util.spin.message('Loading...'); util.spin.start(); + // check for portal-is-running is done here return config.getCommon(this.options) .then(function(r) { bbrest = r.bbrest; From 6c5166a7f743cbb9fc0b69fdd2b546c6dfb9d444 Mon Sep 17 00:00:00 2001 From: Dmytro Medun Date: Mon, 20 Jun 2016 10:20:01 +0200 Subject: [PATCH 2/5] LF-1069: verbose flag for raw error response displaying --- commands/import.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/commands/import.js b/commands/import.js index 2053b9e..be4cb5a 100644 --- a/commands/import.js +++ b/commands/import.js @@ -13,6 +13,7 @@ var JSZip = require('jszip'); var Command = require('ronin').Command; var bbrest, jxon, cfg; +var unknownImportError = 'Unknown import message.'; module.exports = Command.extend({ help: function () { @@ -30,6 +31,7 @@ module.exports = Command.extend({ r += ' -u, --username \t\t' + d('admin') + '\t\tUsername.\n'; r += ' -w, --password \t\t' + d('admin') + '\t\tPassword.\n'; r += ' -p, --portal \t\t\t\tName of the portal on the server to target.\n'; + r += ' -v, --verbose \t\t\t\tPrints out raw error.\n'; r += '\n ' + title('Examples') + ':\n\n'; r += ' bb import --target myPortal.xml\t\t\tImports portal from myPortal.xml\n'; r += ' bb import --target chunked\t\t\tImports bb export chunked portal from chunked dir\n'; @@ -40,15 +42,13 @@ module.exports = Command.extend({ target: {type: 'string', alias: 't'}, dashboard: {type: 'boolean', alias: 'd'}, save: {type: 'string', alias: 's'}, - portal: {type: 'string', alias: 'p'} - //,verbose: {type: 'string', alias: 'v'} + portal: {type: 'string', alias: 'p'}, + verbose: {type: 'boolean', alias: 'v'} }), run: function () { - this.options.verbose = true; util.spin.message('Loading...'); util.spin.start(); - // check for portal-is-running is done here return config.getCommon(this.options) .then(function(r) { bbrest = r.bbrest; @@ -72,10 +72,13 @@ module.exports = Command.extend({ throw new Error('Target is not directory or file.'); }) .then(function(bbr) { - if (bbr.error) { + if (bbr.error === true) { var emsg = jxon.stringToJs(bbr.body); - emsg = emsg.errorMessage || emsg.importErrorMessage || {message: 'Unknown import message.'}; + emsg = emsg.errorMessage || emsg.importErrorMessage || {message: unknownImportError}; throw new Error(emsg.message); + } else if (bbr.error === undefined) { + // handles errorous responses which don't have .error property + throw new Error(cfg.verbose === true ? bbr : unknownImportError); } else ok(bbr); }) .catch(function(err) { From 8110b1a5d578c3668f6123e10a5d91331c268c75 Mon Sep 17 00:00:00 2001 From: Dmytro Medun Date: Mon, 20 Jun 2016 12:26:07 +0200 Subject: [PATCH 3/5] LF-1069: added -o/--timeout option processing, added defaultTimeout 10000 --- commands/import.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/commands/import.js b/commands/import.js index be4cb5a..5d66838 100644 --- a/commands/import.js +++ b/commands/import.js @@ -14,6 +14,7 @@ var Command = require('ronin').Command; var bbrest, jxon, cfg; var unknownImportError = 'Unknown import message.'; +var defaultTimeout = 10000; module.exports = Command.extend({ help: function () { @@ -32,6 +33,7 @@ module.exports = Command.extend({ r += ' -w, --password \t\t' + d('admin') + '\t\tPassword.\n'; r += ' -p, --portal \t\t\t\tName of the portal on the server to target.\n'; r += ' -v, --verbose \t\t\t\tPrints out raw error.\n'; + r += ' -o, --timeout \t\t\t\tMax number of seconds that process can take.\n'; r += '\n ' + title('Examples') + ':\n\n'; r += ' bb import --target myPortal.xml\t\t\tImports portal from myPortal.xml\n'; r += ' bb import --target chunked\t\t\tImports bb export chunked portal from chunked dir\n'; @@ -43,10 +45,16 @@ module.exports = Command.extend({ dashboard: {type: 'boolean', alias: 'd'}, save: {type: 'string', alias: 's'}, portal: {type: 'string', alias: 'p'}, - verbose: {type: 'boolean', alias: 'v'} + verbose: {type: 'boolean', alias: 'v'}, + timeout: {type: 'string', alias: 'o'} }), run: function () { + + // if timeout < 100 ? multiply by 1000 : use as is. + var timeout = +this.options.timeout > 0 && +this.options.timeout || defaultTimeout; + this.options.timeout = timeout > 100 && timeout || timeout * 1000; + util.spin.message('Loading...'); util.spin.start(); return config.getCommon(this.options) @@ -197,6 +205,7 @@ function importDashboard() { username: bbrc.username, password: bbrc.password }, + timeout: bbrc.timeout, headers: { Pragma: 'no-cache', 'Accept-Encoding': 'gzip, deflate', From 6c5bccdd3cb8999abefd3792a156430c9303eaf2 Mon Sep 17 00:00:00 2001 From: Dmytro Medun Date: Mon, 20 Jun 2016 12:26:44 +0200 Subject: [PATCH 4/5] LF-1069: added timeout key into valid options list --- lib/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config.js b/lib/config.js index d6709f8..bc31360 100644 --- a/lib/config.js +++ b/lib/config.js @@ -88,7 +88,7 @@ exports.getCommon = function (cliConfig) { bbrest = new BBRest(); // merge .bbrc properties - var cnames = ['scheme', 'host', 'port', 'context', 'username', 'password', 'portal']; + var cnames = ['scheme', 'host', 'port', 'context', 'username', 'password', 'portal', 'timeout']; _.merge(bbrest.config, _.pick(config.bbrc, cnames)); _.merge(bbrest.config, _.pick(config.cli, cnames)); From 2f36dbde2bef79dc2b73dbed0ac8ffae00970309 Mon Sep 17 00:00:00 2001 From: Dmytro Medun Date: Tue, 21 Jun 2016 17:40:52 +0200 Subject: [PATCH 5/5] LF-1069: updates for error displaying and --verbose flag --- commands/import.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/commands/import.js b/commands/import.js index 5d66838..07c4b99 100644 --- a/commands/import.js +++ b/commands/import.js @@ -80,14 +80,17 @@ module.exports = Command.extend({ throw new Error('Target is not directory or file.'); }) .then(function(bbr) { - if (bbr.error === true) { - var emsg = jxon.stringToJs(bbr.body); - emsg = emsg.errorMessage || emsg.importErrorMessage || {message: unknownImportError}; - throw new Error(emsg.message); - } else if (bbr.error === undefined) { - // handles errorous responses which don't have .error property - throw new Error(cfg.verbose === true ? bbr : unknownImportError); - } else ok(bbr); + if (bbr.error === false) { + ok(bbr); + } else { + if (cfg.verbose === true) { + throw new Error(formattor(bbr, {method: 'json'})); + } else { + var emsg = jxon.stringToJs(bbr.body); + emsg = emsg.errorMessage || emsg.importErrorMessage || {message: unknownImportError}; + throw new Error(emsg.message); + } + } }) .catch(function(err) { if (err.code === 'ENOENT') return error(new Error('Target does not exist.'));