npmci/ts/npmci.ssh.ts

24 lines
876 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-24 00:54:55 +00:00
let sshRegex = /^(.*)\|?(.*)\|?(.*)/
let sshInstance:plugins.smartssh.SshInstance;
2016-06-23 20:22:03 +00:00
export let ssh = () => {
2016-06-24 00:54:55 +00:00
sshInstance = new plugins.smartssh.SshInstance();
2016-06-23 20:22:03 +00:00
plugins.smartparam.forEachMinimatch(process.env,"NPMCI_SSHKEY_*",evaluateSshkey);
2016-06-24 00:54:55 +00:00
sshInstance.sync("to");
2016-06-23 20:22:03 +00:00
};
2016-06-24 00:54:55 +00:00
export let evaluateSshkey = (sshkeyEnvVarArg) => {
let resultArray = sshRegex.exec(sshkeyEnvVarArg);
let sshKey = new plugins.smartssh.SshKey();
if(resultArray[1] && resultArray[1] != "undefined") sshKey.privateKeyBase64 = resultArray[1];
let publicKey:string;
if(resultArray[2] && resultArray[2] != "undefined") sshKey.publicKeyBase64 = resultArray[2];
let host:string;
if(resultArray[3] && resultArray[3] != "undefined") sshKey.host = resultArray[1];
2016-06-23 20:22:03 +00:00
2016-06-24 00:54:55 +00:00
sshInstance.addKey(sshKey);
2016-06-23 20:22:03 +00:00
};