Skip to content

Commit 3306d30

Browse files
committed
Get proper path to local keyfile when selected
1 parent 6516e0d commit 3306d30

5 files changed

Lines changed: 25 additions & 7 deletions

File tree

editor/js/ui/projects/projects.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ RED.projects = (function() {
941941
remotes: {
942942
'origin': {
943943
url: repoUrl,
944-
key_file: selected,
944+
keyFile: selected,
945945
passphrase: projectRepoPassphrase.val()
946946
}
947947
}

red/api/editor/projects/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@ module.exports = {
338338
res.status(204).end();
339339
})
340340
.catch(function(err) {
341-
console.log(err.stack);
342341
if (err.code) {
343342
res.status(400).json({error:err.code, message: err.message});
344343
} else {

red/runtime/storage/localfilesystem/projects/Project.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var os = require('os');
2323
var gitTools = require("./git");
2424
var util = require("../util");
2525
var defaultFileSet = require("./defaultFileSet");
26-
26+
var sshKeys = require("../sshkeys");
2727
var settings;
2828
var runtime;
2929
var log;
@@ -645,7 +645,7 @@ Project.prototype.updateRemote = function(user,remote,options) {
645645
if (options.auth) {
646646
var url = this.remotes[remote].fetch;
647647
if (options.auth.keyFile) {
648-
options.auth.key_path = fspath.join(projectsDir, ".sshkeys", ((username === '_')?'__default':username) + '_' + options.auth.keyFile);
648+
options.auth.key_path = sshKeys.getPrivateKeyPath(username, options.auth.keyFile);
649649
}
650650
authCache.set(this.name,url,username,options.auth);
651651
}
@@ -870,10 +870,9 @@ function createProject(user, metadata) {
870870
);
871871
auth = authCache.get(project,originRemote.url,username);
872872
}
873-
else if (originRemote.hasOwnProperty("key_file") && originRemote.hasOwnProperty("passphrase")) {
874-
var key_file_name = (username === '_') ? '__default' + '_' + originRemote.key_file : username + '_' + originRemote.key_file;
873+
else if (originRemote.hasOwnProperty("keyFile") && originRemote.hasOwnProperty("passphrase")) {
875874
authCache.set(project,originRemote.url,username,{ // TODO: hardcoded remote name
876-
key_path: fspath.join(projectsDir, ".sshkeys", key_file_name),
875+
key_path: sshKeys.getPrivateKeyPath(username, originRemote.keyFile),
877876
passphrase: originRemote.passphrase
878877
}
879878
);

red/runtime/storage/localfilesystem/projects/git/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,8 @@ module.exports = {
444444
err.code = 'git_push_failed';
445445
}
446446
throw err;
447+
} else {
448+
throw err;
447449
}
448450
});
449451
},

red/runtime/storage/localfilesystem/sshkeys.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,28 @@ function generateSSHKeyPair(name, privateKeyPath, comment, password, size) {
186186
});
187187
}
188188

189+
function getPrivateKeyPath(username, name) {
190+
var sshKeyFileBasename = username + '_' + name;
191+
var privateKeyFilePath = fspath.join(sshkeyDir, sshKeyFileBasename);
192+
try {
193+
fs.accessSync(privateKeyFilePath, (fs.constants || fs).R_OK);
194+
return privateKeyFilePath;
195+
} catch(err) {
196+
privateKeyFilePath = fspath.join(userSSHKeyDir,name);
197+
try {
198+
fs.accessSync(privateKeyFilePath, (fs.constants || fs).R_OK);
199+
return privateKeyFilePath;
200+
} catch(err2) {
201+
return null;
202+
}
203+
}
204+
}
205+
189206
module.exports = {
190207
init: init,
191208
listSSHKeys: listSSHKeys,
192209
getSSHKey: getSSHKey,
210+
getPrivateKeyPath: getPrivateKeyPath,
193211
generateSSHKey: generateSSHKey,
194212
deleteSSHKey: deleteSSHKey
195213
};

0 commit comments

Comments
 (0)