nscale-util
Advanced tools
Comparing version 0.4.0 to 0.10.0
@@ -18,2 +18,3 @@ /* | ||
var exec = require('child_process').exec; | ||
var bunyan = require('bunyan'); | ||
@@ -25,43 +26,57 @@ | ||
*/ | ||
exports.exec = function(mode, cmd, dir, out, cb) { | ||
var proc; | ||
var targetPath = '.'; | ||
var errmsg = ''; | ||
module.exports = function(logger) { | ||
logger = logger || bunyan.createLogger({name: 'nscale-util'}); | ||
if ('preview' === mode) { | ||
cb(null, null, cmd); | ||
} | ||
else { | ||
proc = exec(cmd, {cwd: dir}); | ||
proc.stdout.on('data', function (data) { | ||
if (data.indexOf('TARGET:') !== -1) { | ||
targetPath = data.substr(7); | ||
targetPath = targetPath.trim(); | ||
} | ||
else { | ||
targetPath = '.'; | ||
} | ||
out.stdout(data); | ||
}); | ||
var execute = function(mode, cmd, dir, out, cb) { | ||
var proc; | ||
var targetPath = '.'; | ||
var errmsg = ''; | ||
proc.stderr.on('data', function (data) { | ||
out.stderr(data); | ||
errmsg += data; | ||
}); | ||
logger.info('executor: ' + cmd + ', in: ' + dir); | ||
if ('preview' === mode) { | ||
cb(null, null, cmd); | ||
} | ||
else { | ||
proc = exec(cmd, {cwd: dir}); | ||
proc.stdout.on('data', function (data) { | ||
if (data.indexOf('TARGET:') !== -1) { | ||
targetPath = data.substr(7); | ||
targetPath = targetPath.trim(); | ||
} | ||
else { | ||
targetPath = '.'; | ||
} | ||
out.stdout(data); | ||
//logger.debug('executor: ' + cmd + ', in: ' + dir + ', stdout: ' + data); | ||
logger.info('executor: ' + cmd + ', in: ' + dir + ', stdout: ' + data); | ||
}); | ||
proc.on('close', function (code) { | ||
var err; | ||
if (code !== 0) { | ||
err = new Error('command failed') | ||
err.cmd = cmd; | ||
err.code = code; | ||
cb(err, targetPath, cmd); | ||
} | ||
else { | ||
cb(null, targetPath, cmd); | ||
} | ||
}); | ||
} | ||
proc.stderr.on('data', function (data) { | ||
out.stderr(data); | ||
errmsg += data; | ||
logger.error('executor: ' + cmd + ', in: ' + dir + ', stderr: ' + errmsg); | ||
}); | ||
proc.on('close', function (code) { | ||
var err; | ||
if (code !== 0) { | ||
logger.error('executor: ' + cmd + ', in: ' + dir + ', FAILED!: ' + code); | ||
err = new Error('command failed'); | ||
err.cmd = cmd; | ||
err.code = code; | ||
cb(err, targetPath, cmd); | ||
} | ||
else { | ||
logger.info('executor: ' + cmd + ', in: ' + dir + ', OK!'); | ||
cb(null, targetPath, cmd); | ||
} | ||
}); | ||
} | ||
}; | ||
return { | ||
exec: execute | ||
}; | ||
}; | ||
@@ -17,10 +17,7 @@ /* | ||
exports.docker = function() { return require('./docker'); }; | ||
exports.dockerBuilder = function(config, platform) { return require('./dockerBuilder')(config, platform); }; | ||
exports.paths = function() { return require('./paths'); }; | ||
exports.sshcp = function() { return require('./sshcp')(); }; | ||
exports.sshexec = function() { return require('./sshexec')(); }; | ||
exports.sshcheck = function() { return require('./sshCheck')(); }; | ||
exports.executor = function() { return require('./executor'); }; | ||
exports.sshcp = function(logger) { return require('./sshcp')(logger); }; | ||
exports.sshexec = function(logger) { return require('./sshexec')(logger); }; | ||
exports.sshcheck = function(logger) { return require('./sshCheck')(logger); }; | ||
exports.executor = function(logger) { return require('./executor')(logger); }; | ||
exports.recursor = function() { return require('./recursor'); }; | ||
exports.sysdef = function() { return require('./sysdef'); }; |
@@ -17,3 +17,3 @@ /* | ||
var executor = require('./executor'); | ||
var bunyan = require('bunyan'); | ||
@@ -43,3 +43,5 @@ | ||
module.exports = function() { | ||
module.exports = function(logger) { | ||
var executor = require('./executor')(logger); | ||
logger = logger || bunyan.createLogger({name: 'nscale-util'}); | ||
@@ -56,2 +58,3 @@ var check = function(host, user, keyPath, out, cb) { | ||
} | ||
logger.info('sshcheck: ' + cmd); | ||
var op = {cmd: cmd, | ||
@@ -64,2 +67,3 @@ host: host, | ||
if (w.output().indexOf('Permission denied') !== -1 || w.output().indexOf('Authentication failure') !== -1) { | ||
logger.error('sshcheck ERROR: ' + w.output); | ||
cb(new Error('permission denied - possible ssh key or key password problem')); | ||
@@ -66,0 +70,0 @@ } |
@@ -17,3 +17,3 @@ /* | ||
var executor = require('./executor'); | ||
var bunyan = require('bunyan'); | ||
@@ -25,3 +25,5 @@ | ||
*/ | ||
module.exports = function() { | ||
module.exports = function(logger) { | ||
var executor = require('./executor')(logger); | ||
logger = logger || bunyan.createLogger({name: 'nscale-util'}); | ||
@@ -34,2 +36,3 @@ var copy = function(mode, host, user, keyPath, sourcePath, targetPath, out, cb) { | ||
logger.info('sshcp: ' + op.cmd); | ||
if ('preview' === mode) { | ||
@@ -36,0 +39,0 @@ cb(null, op); |
@@ -19,2 +19,3 @@ /* | ||
var fs = require('fs'); | ||
var bunyan = require('bunyan'); | ||
@@ -25,3 +26,4 @@ | ||
*/ | ||
module.exports = function() { | ||
module.exports = function(logger) { | ||
logger = logger || bunyan.createLogger({name: 'nscale-util'}); | ||
@@ -34,2 +36,3 @@ var exec = function(mode, host, user, keyPath, command, cb) { | ||
logger.info('sshexec: ' + command + ', on: ' + host + ',user: ' + user + ',key: ' + keyPath); | ||
if ('preview' === mode) { | ||
@@ -42,2 +45,3 @@ cb(null, op); | ||
c.on('ready', function() { | ||
logger.info('sshexec: ' + command + ', on: ' + host + ',ready!'); | ||
c.exec(command, function(err, stream) { | ||
@@ -47,2 +51,3 @@ if (err) { return cb(err, op); } | ||
response += data.toString(); | ||
logger.info('sshexec: ' + command + ', on: ' + host + ',stdout: ' + response); | ||
}); | ||
@@ -58,2 +63,3 @@ stream.on('end', function() { | ||
response += data.toString(); | ||
logger.error('sshexec: ' + command + ', on: ' + host + ',stderr: ' + response); | ||
}); | ||
@@ -63,2 +69,3 @@ }); | ||
c.on('error', function(err) { | ||
logger.error('sshexec: ' + command + ', on: ' + host + ',ERROR!:' + err); | ||
cb(err, op); | ||
@@ -71,2 +78,3 @@ c.removeAllListeners('close'); | ||
c.on('close', function() { | ||
logger.error('sshexec: ' + command + ', on: ' + host + ',done!'); | ||
cb(null, op, response); | ||
@@ -73,0 +81,0 @@ }); |
@@ -10,3 +10,3 @@ { | ||
], | ||
"version": "0.4.0", | ||
"version": "0.10.0", | ||
"license": "Artistic License 2.0", | ||
@@ -36,2 +36,2 @@ "author": "Peter Elger (http://nearform.com/)", | ||
"scripts": {} | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
2
43763
27
843