1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Get proper path to local keyfile when selected

This commit is contained in:
Nick O'Leary 2018-01-11 11:19:04 +00:00
parent 6516e0dfd2
commit 3306d30094
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
5 changed files with 25 additions and 7 deletions

View File

@ -941,7 +941,7 @@ RED.projects = (function() {
remotes: { remotes: {
'origin': { 'origin': {
url: repoUrl, url: repoUrl,
key_file: selected, keyFile: selected,
passphrase: projectRepoPassphrase.val() passphrase: projectRepoPassphrase.val()
} }
} }

View File

@ -338,7 +338,6 @@ module.exports = {
res.status(204).end(); res.status(204).end();
}) })
.catch(function(err) { .catch(function(err) {
console.log(err.stack);
if (err.code) { if (err.code) {
res.status(400).json({error:err.code, message: err.message}); res.status(400).json({error:err.code, message: err.message});
} else { } else {

View File

@ -23,7 +23,7 @@ var os = require('os');
var gitTools = require("./git"); var gitTools = require("./git");
var util = require("../util"); var util = require("../util");
var defaultFileSet = require("./defaultFileSet"); var defaultFileSet = require("./defaultFileSet");
var sshKeys = require("../sshkeys");
var settings; var settings;
var runtime; var runtime;
var log; var log;
@ -645,7 +645,7 @@ Project.prototype.updateRemote = function(user,remote,options) {
if (options.auth) { if (options.auth) {
var url = this.remotes[remote].fetch; var url = this.remotes[remote].fetch;
if (options.auth.keyFile) { if (options.auth.keyFile) {
options.auth.key_path = fspath.join(projectsDir, ".sshkeys", ((username === '_')?'__default':username) + '_' + options.auth.keyFile); options.auth.key_path = sshKeys.getPrivateKeyPath(username, options.auth.keyFile);
} }
authCache.set(this.name,url,username,options.auth); authCache.set(this.name,url,username,options.auth);
} }
@ -870,10 +870,9 @@ function createProject(user, metadata) {
); );
auth = authCache.get(project,originRemote.url,username); auth = authCache.get(project,originRemote.url,username);
} }
else if (originRemote.hasOwnProperty("key_file") && originRemote.hasOwnProperty("passphrase")) { else if (originRemote.hasOwnProperty("keyFile") && originRemote.hasOwnProperty("passphrase")) {
var key_file_name = (username === '_') ? '__default' + '_' + originRemote.key_file : username + '_' + originRemote.key_file;
authCache.set(project,originRemote.url,username,{ // TODO: hardcoded remote name authCache.set(project,originRemote.url,username,{ // TODO: hardcoded remote name
key_path: fspath.join(projectsDir, ".sshkeys", key_file_name), key_path: sshKeys.getPrivateKeyPath(username, originRemote.keyFile),
passphrase: originRemote.passphrase passphrase: originRemote.passphrase
} }
); );

View File

@ -444,6 +444,8 @@ module.exports = {
err.code = 'git_push_failed'; err.code = 'git_push_failed';
} }
throw err; throw err;
} else {
throw err;
} }
}); });
}, },

View File

@ -186,10 +186,28 @@ function generateSSHKeyPair(name, privateKeyPath, comment, password, size) {
}); });
} }
function getPrivateKeyPath(username, name) {
var sshKeyFileBasename = username + '_' + name;
var privateKeyFilePath = fspath.join(sshkeyDir, sshKeyFileBasename);
try {
fs.accessSync(privateKeyFilePath, (fs.constants || fs).R_OK);
return privateKeyFilePath;
} catch(err) {
privateKeyFilePath = fspath.join(userSSHKeyDir,name);
try {
fs.accessSync(privateKeyFilePath, (fs.constants || fs).R_OK);
return privateKeyFilePath;
} catch(err2) {
return null;
}
}
}
module.exports = { module.exports = {
init: init, init: init,
listSSHKeys: listSSHKeys, listSSHKeys: listSSHKeys,
getSSHKey: getSSHKey, getSSHKey: getSSHKey,
getPrivateKeyPath: getPrivateKeyPath,
generateSSHKey: generateSSHKey, generateSSHKey: generateSSHKey,
deleteSSHKey: deleteSSHKey deleteSSHKey: deleteSSHKey
}; };