diff --git a/editor/js/ui/projects/projects.js b/editor/js/ui/projects/projects.js index 7cf1a35c7..c1a82bc03 100644 --- a/editor/js/ui/projects/projects.js +++ b/editor/js/ui/projects/projects.js @@ -941,7 +941,7 @@ RED.projects = (function() { remotes: { 'origin': { url: repoUrl, - key_file: selected, + keyFile: selected, passphrase: projectRepoPassphrase.val() } } diff --git a/red/api/editor/projects/index.js b/red/api/editor/projects/index.js index 4860ded3d..608c6caae 100644 --- a/red/api/editor/projects/index.js +++ b/red/api/editor/projects/index.js @@ -338,7 +338,6 @@ module.exports = { res.status(204).end(); }) .catch(function(err) { - console.log(err.stack); if (err.code) { res.status(400).json({error:err.code, message: err.message}); } else { diff --git a/red/runtime/storage/localfilesystem/projects/Project.js b/red/runtime/storage/localfilesystem/projects/Project.js index 27b9e419b..0d5939673 100644 --- a/red/runtime/storage/localfilesystem/projects/Project.js +++ b/red/runtime/storage/localfilesystem/projects/Project.js @@ -23,7 +23,7 @@ var os = require('os'); var gitTools = require("./git"); var util = require("../util"); var defaultFileSet = require("./defaultFileSet"); - +var sshKeys = require("../sshkeys"); var settings; var runtime; var log; @@ -645,7 +645,7 @@ Project.prototype.updateRemote = function(user,remote,options) { if (options.auth) { var url = this.remotes[remote].fetch; 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); } @@ -870,10 +870,9 @@ function createProject(user, metadata) { ); auth = authCache.get(project,originRemote.url,username); } - else if (originRemote.hasOwnProperty("key_file") && originRemote.hasOwnProperty("passphrase")) { - var key_file_name = (username === '_') ? '__default' + '_' + originRemote.key_file : username + '_' + originRemote.key_file; + else if (originRemote.hasOwnProperty("keyFile") && originRemote.hasOwnProperty("passphrase")) { 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 } ); diff --git a/red/runtime/storage/localfilesystem/projects/git/index.js b/red/runtime/storage/localfilesystem/projects/git/index.js index bc6b066f3..071ede76a 100644 --- a/red/runtime/storage/localfilesystem/projects/git/index.js +++ b/red/runtime/storage/localfilesystem/projects/git/index.js @@ -444,6 +444,8 @@ module.exports = { err.code = 'git_push_failed'; } throw err; + } else { + throw err; } }); }, diff --git a/red/runtime/storage/localfilesystem/sshkeys.js b/red/runtime/storage/localfilesystem/sshkeys.js index daaa0b570..6a02de210 100644 --- a/red/runtime/storage/localfilesystem/sshkeys.js +++ b/red/runtime/storage/localfilesystem/sshkeys.js @@ -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 = { init: init, listSSHKeys: listSSHKeys, getSSHKey: getSSHKey, + getPrivateKeyPath: getPrivateKeyPath, generateSSHKey: generateSSHKey, deleteSSHKey: deleteSSHKey };