Skip to content
This repository was archived by the owner on Jul 2, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions commands/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ var JSZip = require('jszip');
var Command = require('ronin').Command;

var bbrest, jxon, cfg;
var unknownImportError = 'Unknown import message.';
var defaultTimeout = 10000;

module.exports = Command.extend({
help: function () {
Expand All @@ -30,6 +32,8 @@ module.exports = Command.extend({
r += ' -u, --username <string>\t\t' + d('admin') + '\t\tUsername.\n';
r += ' -w, --password <string>\t\t' + d('admin') + '\t\tPassword.\n';
r += ' -p, --portal <string>\t\t\t\tName of the portal on the server to target.\n';
r += ' -v, --verbose <string>\t\t\t\tPrints out raw error.\n';
r += ' -o, --timeout <string>\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';
Expand All @@ -40,11 +44,17 @@ module.exports = Command.extend({
target: {type: 'string', alias: 't'},
dashboard: {type: 'boolean', alias: 'd'},
save: {type: 'string', alias: 's'},
portal: {type: 'string', alias: 'p'}
portal: {type: 'string', alias: 'p'},
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)
Expand All @@ -70,11 +80,17 @@ module.exports = Command.extend({
throw new Error('Target is not directory or file.');
})
.then(function(bbr) {
if (bbr.error) {
var emsg = jxon.stringToJs(bbr.body);
emsg = emsg.errorMessage || emsg.importErrorMessage || {message: 'Unknown import message.'};
throw new Error(emsg.message);
} 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.'));
Expand Down Expand Up @@ -192,6 +208,7 @@ function importDashboard() {
username: bbrc.username,
password: bbrc.password
},
timeout: bbrc.timeout,
headers: {
Pragma: 'no-cache',
'Accept-Encoding': 'gzip, deflate',
Expand Down
2 changes: 1 addition & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down