Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adds host.logMask masking of portions of command from console and log…

… file.
  • Loading branch information...
commit b351f6f43503e007b92bea379ad6362a3aba67de 1 parent f5be12a
@tsmith authored
Showing with 33 additions and 1 deletion.
  1. +3 −0  CHANGELOG
  2. +12 −0 README
  3. +18 −1 lib/host.js
View
3  CHANGELOG
@@ -1,3 +1,6 @@
+0.1.7
+- Add host.logMask to allow masking things like passwords from command logging
+
0.1.6
- Document sshOptions and reimplement to allow setting in config or host object
- Remove undocumented host() method for setting up a single host from config
View
12 README
@@ -346,10 +346,22 @@ the host address so, for example:
grep myhost1.mydomain.com hosts.log | less
+
Would allow paging the log and seeing only lines pertaining to
myhost1.mydomain.com.
+If you send something you do not want to get logged (like a password) in a
+command, use the log mask:
+
+host.logMask = secret;
+host.ssh('echo ' + secret + ' > file.txt');
+
+
+The console and command log file will show the masked text as asterisks instead
+of the actual text.
+
+
SSH
View
19 lib/host.js
@@ -27,6 +27,15 @@ function listen(subProcess, log, callback) {
});
}
+function star(mask) {
+ var stars = '',
+ i, length;
+ for (i = 0, length = mask.length; i < length; i += 1) {
+ stars += '*';
+ }
+ return stars;
+}
+
function ssh(command, callback) {
if (!command) {
throw new Error(this.address + ': No command to run');
@@ -35,13 +44,21 @@ function ssh(command, callback) {
var log = this.logger,
user = this.user,
options = this.sshOptions,
+ mask = this.logMask, stars,
args = ['-l' + user, this.address, "''" + command + "''"],
subProcess;
-
+
if (options) {
args = options.concat(args);
}
+ if (mask) {
+ stars = star(mask);
+ while (command.indexOf(mask) !== -1) {
+ command = command.replace(mask, stars);
+ }
+ }
+
log.puts(user + ':ssh ' + command);
subProcess = spawn('ssh', args);
listen(subProcess, log, callback);
Please sign in to comment.
Something went wrong with that request. Please try again.