npmci/ts/npmci.ssh.ts

29 lines
957 B
TypeScript
Raw Normal View History

2016-06-23 20:22:03 +00:00
import "typings-global";
import * as plugins from "./npmci.plugins";
2016-06-25 16:53:35 +00:00
let sshRegex = /^(.*)\|(.*)\|(.*)/
2016-06-24 00:54:55 +00:00
let sshInstance:plugins.smartssh.SshInstance;
2016-06-23 20:22:03 +00:00
export let ssh = () => {
2016-06-25 14:29:06 +00:00
let done = plugins.q.defer();
2016-06-24 00:54:55 +00:00
sshInstance = new plugins.smartssh.SshInstance();
2016-06-25 14:29:06 +00:00
plugins.smartparam.forEachMinimatch(process.env,"NPMCI_SSHKEY_*",evaluateSshEnv);
2016-06-25 00:55:36 +00:00
sshInstance.writeToDisk();
2016-06-25 14:29:06 +00:00
done.resolve();
return done.promise;
2016-06-23 20:22:03 +00:00
};
2016-06-25 14:29:06 +00:00
let evaluateSshEnv = (sshkeyEnvVarArg) => {
2016-06-24 00:54:55 +00:00
let resultArray = sshRegex.exec(sshkeyEnvVarArg);
let sshKey = new plugins.smartssh.SshKey();
2016-06-25 16:53:35 +00:00
if(notUndefined(resultArray[1])) sshKey.host = resultArray[1];
if(notUndefined(resultArray[2])) sshKey.privKeyBase64 = resultArray[2];
if(notUndefined(resultArray[3])) sshKey.pubKeyBase64 = resultArray[3];
2016-06-23 20:22:03 +00:00
2016-06-24 00:54:55 +00:00
sshInstance.addKey(sshKey);
2016-06-25 16:53:35 +00:00
};
let notUndefined = (stringArg:string) => {
return (stringArg && stringArg != "undefined" && stringArg != "##")
}