now has better sshKey understanding

This commit is contained in:
2016-06-28 02:45:37 +02:00
parent f0cab00277
commit 14492ff7a8
7 changed files with 41 additions and 21 deletions

View File

@ -2,36 +2,45 @@ import "typings-global"
import plugins = require("./smartgit.plugins");
import SmartgitCheck = require("./smartgit.check");
export let clone = (options:{from:string,to:string}) => {
export let clone = (optionsArg:{
from:string,
to:string,
keyPath?:string,
keyPassphrase?:string
}) => {
let done = plugins.Q.defer();
/***** URL Checks ******/
//TODO make smartstring URL test
/***** Path Checks ******/
if (!/^\/.*/.test(options.to)){ //check wether path is absolute
plugins.beautylog.error("It seems that the given path " + options.to + " is not absolute.");
if (!/^\/.*/.test(optionsArg.to)){ //check wether path is absolute
plugins.beautylog.error("It seems that the given path " + optionsArg.to + " is not absolute.");
return;
}
plugins.beautylog.log("Now cloning " + options.from);
plugins.beautylog.log("Now cloning " + optionsArg.from);
var cloneOptions:any = {
fetchOpts: {
callbacks: {
certificateCheck: function() { return 1; },
credentials: function(url, userName) {
let gitRepo = new plugins.smartstring.GitRepo(url);
let sshDirPath:string;
let pubKey:string;
let privKey:string;
return plugins.nodegit.Cred.sshKeyMemoryNew(userName, pubKey, privKey, "");
let host = gitRepo.host;
let sshDir = plugins.path.join(plugins.smartpath.get.home(),".ssh/")
let pubKeyPath = plugins.path.join(sshDir,host + ".pub");
let privKeyPath:string = plugins.path.join(sshDir,host);
if(!optionsArg.keyPassphrase) optionsArg.keyPassphrase = "";
return plugins.nodegit.Cred.sshKeyNew(userName, pubKeyPath, privKeyPath,optionsArg.keyPassphrase);
}
}
}
};
var cloneRepository = plugins.nodegit.Clone.clone(options.from, options.to, cloneOptions)
var cloneRepository = plugins.nodegit.Clone.clone(optionsArg.from, optionsArg.to, cloneOptions)
.then(() => {
SmartgitCheck(cloneRepository);
done.resolve();
},(err) => {
console.log(err);
});
return done.promise;
};

View File

@ -5,6 +5,7 @@ export import beautylog = require("beautylog");
export let nodegit = require("nodegit");
export let Q = require("q");
export import smartfile = require("smartfile");
export import smartpath = require("smartpath");
export import smartstring = require("smartstring");