mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Fix reauthentication of remote repositories
This commit is contained in:
@@ -120,12 +120,14 @@ Project.prototype.loadRemotes = function() {
|
||||
}).then(function() {
|
||||
var allRemotes = Object.keys(project.remotes);
|
||||
var match = "";
|
||||
allRemotes.forEach(function(remote) {
|
||||
if (project.branches.remote.indexOf(remote) === 0 && match.length < remote.length) {
|
||||
match = remote;
|
||||
}
|
||||
});
|
||||
project.currentRemote = project.parseRemoteBranch(project.branches.remote).remote;
|
||||
if (project.branches.remote) {
|
||||
allRemotes.forEach(function(remote) {
|
||||
if (project.branches.remote.indexOf(remote) === 0 && match.length < remote.length) {
|
||||
match = remote;
|
||||
}
|
||||
});
|
||||
project.currentRemote = project.parseRemoteBranch(project.branches.remote).remote;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -541,8 +543,21 @@ Project.prototype.addRemote = function(user,remote,options) {
|
||||
});
|
||||
}
|
||||
Project.prototype.updateRemote = function(user,remote,options) {
|
||||
// TODO: once the sshkey support is added, move the updating of remotes,
|
||||
// including their auth details, down here.
|
||||
var username;
|
||||
if (!user) {
|
||||
username = "_";
|
||||
} else {
|
||||
username = user.username;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
authCache.set(this.name,url,username,options.auth);
|
||||
}
|
||||
return Promise.resolve();
|
||||
}
|
||||
Project.prototype.removeRemote = function(user, remote) {
|
||||
// TODO: if this was the last remote using this url, then remove the authCache
|
||||
@@ -764,7 +779,7 @@ 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;
|
||||
var key_file_name = (username === '_') ? '__default' + '_' + originRemote.key_file : username + '_' + originRemote.key_file;
|
||||
authCache.set(project,originRemote.url,username,{ // TODO: hardcoded remote name
|
||||
key_path: fspath.join(projectsDir, ".sshkeys", key_file_name),
|
||||
passphrase: originRemote.passphrase
|
||||
|
@@ -266,6 +266,10 @@ function removeRemote(user, project, remote) {
|
||||
checkActiveProject(project);
|
||||
return activeProject.removeRemote(user, remote);
|
||||
}
|
||||
function updateRemote(user, project, remote, body) {
|
||||
checkActiveProject(project);
|
||||
return activeProject.updateRemote(user, remote, body);
|
||||
}
|
||||
|
||||
function getActiveProject(user) {
|
||||
return activeProject;
|
||||
@@ -491,6 +495,7 @@ module.exports = {
|
||||
getRemotes: getRemotes,
|
||||
addRemote: addRemote,
|
||||
removeRemote: removeRemote,
|
||||
updateRemote: updateRemote,
|
||||
|
||||
getFlows: getFlows,
|
||||
saveFlows: saveFlows,
|
||||
|
Reference in New Issue
Block a user