Merge sshkeys

This commit is contained in:
Nick O'Leary
2017-12-20 15:12:10 +00:00
14 changed files with 1704 additions and 82 deletions

View File

@@ -18,6 +18,7 @@ var when = require('when');
var exec = require('child_process').exec;
var spawn = require('child_process').spawn;
var authResponseServer = require('./authServer').ResponseServer;
var sshResponseServer = require('./authServer').ResponseSSHServer;
var clone = require('clone');
var path = require("path");
@@ -50,6 +51,8 @@ function runGitCommand(args,cwd,env) {
err.code = "git_auth_failed";
} else if(/HTTP Basic: Access denied/.test(stderr)) {
err.code = "git_auth_failed";
} else if(/Permission denied \(publickey\)/.test(stderr)) {
err.code = "git_auth_failed";
} else if(/Connection refused/.test(stderr)) {
err.code = "git_connection_failed";
} else if (/commit your changes or stash/.test(stderr)) {
@@ -80,6 +83,22 @@ function runGitCommandWithAuth(args,cwd,auth) {
})
}
function runGitCommandWithSSHCommand(args,cwd,auth) {
return sshResponseServer(auth).then(function(rs) {
var commandEnv = clone(process.env);
commandEnv.SSH_ASKPASS = path.join(__dirname,"node-red-ask-pass.sh");
commandEnv.DISPLAY = "dummy:0";
commandEnv.NODE_RED_GIT_NODE_PATH = process.execPath;
commandEnv.NODE_RED_GIT_SOCK_PATH = rs.path;
commandEnv.NODE_RED_GIT_ASKPASS_PATH = path.join(__dirname,"authWriter.js");
commandEnv.GIT_SSH_COMMAND = "ssh -i " + auth.key_path + " -F /dev/null";
// console.log('commandEnv:', commandEnv);
return runGitCommand(args,cwd,commandEnv).finally(function() {
rs.close();
});
})
}
function cleanFilename(name) {
if (name[0] !== '"') {
return name;
@@ -362,7 +381,12 @@ module.exports = {
}
var promise;
if (auth) {
promise = runGitCommandWithAuth(args,cwd,auth);
if ( auth.key_path ) {
promise = runGitCommandWithSSHCommand(args,cwd,auth);
}
else {
promise = runGitCommandWithAuth(args,cwd,auth);
}
} else {
promise = runGitCommand(args,cwd)
}
@@ -393,7 +417,12 @@ module.exports = {
args.push("--porcelain");
var promise;
if (auth) {
promise = runGitCommandWithAuth(args,cwd,auth);
if ( auth.key_path ) {
promise = runGitCommandWithSSHCommand(args,cwd,auth);
}
else {
promise = runGitCommandWithAuth(args,cwd,auth);
}
} else {
promise = runGitCommand(args,cwd)
}
@@ -418,7 +447,12 @@ module.exports = {
}
args.push(".");
if (auth) {
return runGitCommandWithAuth(args,cwd,auth);
if ( auth.key_path ) {
return runGitCommandWithSSHCommand(args,cwd,auth);
}
else {
return runGitCommandWithAuth(args,cwd,auth);
}
} else {
return runGitCommand(args,cwd);
}
@@ -477,7 +511,12 @@ module.exports = {
fetch: function(cwd,remote,auth) {
var args = ["fetch",remote];
if (auth) {
return runGitCommandWithAuth(args,cwd,auth);
if ( auth.key_path ) {
return runGitCommandWithSSHCommand(args,cwd,auth);
}
else {
return runGitCommandWithAuth(args,cwd,auth);
}
} else {
return runGitCommand(args,cwd);
}