mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	Get proper path to local keyfile when selected
This commit is contained in:
		@@ -941,7 +941,7 @@ RED.projects = (function() {
 | 
			
		||||
                                                remotes: {
 | 
			
		||||
                                                    'origin': {
 | 
			
		||||
                                                        url: repoUrl,
 | 
			
		||||
                                                        key_file: selected,
 | 
			
		||||
                                                        keyFile: selected,
 | 
			
		||||
                                                        passphrase: projectRepoPassphrase.val()
 | 
			
		||||
                                                    }
 | 
			
		||||
                                                }
 | 
			
		||||
 
 | 
			
		||||
@@ -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 {
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
                            }
 | 
			
		||||
                        );
 | 
			
		||||
 
 | 
			
		||||
@@ -444,6 +444,8 @@ module.exports = {
 | 
			
		||||
                    err.code = 'git_push_failed';
 | 
			
		||||
                }
 | 
			
		||||
                throw err;
 | 
			
		||||
            } else {
 | 
			
		||||
                throw err;
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
    },
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user