This commit is contained in:
2016-11-24 23:21:40 +01:00
parent 09c7dae079
commit 299d2567f8
44 changed files with 664 additions and 608 deletions

View File

@@ -1,51 +1,51 @@
import "typings-global";
import * as plugins from "./npmci.plugins";
import 'typings-global'
import * as plugins from './npmci.plugins'
let sshRegex = /^(.*)\|(.*)\|(.*)/
let sshInstance:plugins.smartssh.SshInstance;
let sshInstance: plugins.smartssh.SshInstance
/**
* checks for ENV vars in form of NPMCI_SSHKEY_* and deploys any found ones
*/
export let ssh = () => {
let done = plugins.q.defer();
sshInstance = new plugins.smartssh.SshInstance(); // init ssh instance
plugins.smartparam.forEachMinimatch(process.env,"NPMCI_SSHKEY_*",evaluateSshEnv);
if(!process.env.NPMTS_TEST){
sshInstance.writeToDisk();
let done = plugins.q.defer()
sshInstance = new plugins.smartssh.SshInstance() // init ssh instance
plugins.smartparam.forEachMinimatch(process.env,'NPMCI_SSHKEY_*',evaluateSshEnv)
if (!process.env.NPMTS_TEST) {
sshInstance.writeToDisk()
} else {
plugins.beautylog.log("In test mode, so not storing SSH keys to disk!");
plugins.beautylog.log('In test mode, so not storing SSH keys to disk!')
};
done.resolve();
return done.promise;
};
done.resolve()
return done.promise
}
/**
* gets called for each found SSH ENV Var and deploys it
*/
let evaluateSshEnv = (sshkeyEnvVarArg) => {
let resultArray = sshRegex.exec(sshkeyEnvVarArg);
let sshKey = new plugins.smartssh.SshKey();
plugins.beautylog.info("Found SSH identity for " + resultArray[1]);
if(notUndefined(resultArray[1])){
plugins.beautylog.log("---> host defined!")
sshKey.host = resultArray[1];
let resultArray = sshRegex.exec(sshkeyEnvVarArg)
let sshKey = new plugins.smartssh.SshKey()
plugins.beautylog.info('Found SSH identity for ' + resultArray[1])
if (notUndefined(resultArray[1])) {
plugins.beautylog.log('---> host defined!')
sshKey.host = resultArray[1]
}
if(notUndefined(resultArray[2])){
plugins.beautylog.log("---> privKey defined!")
sshKey.privKeyBase64 = resultArray[2];
if (notUndefined(resultArray[2])) {
plugins.beautylog.log('---> privKey defined!')
sshKey.privKeyBase64 = resultArray[2]
};
if(notUndefined(resultArray[3])){
"---> pubKey defined!"
sshKey.pubKeyBase64 = resultArray[3];
if (notUndefined(resultArray[3])) {
'---> pubKey defined!'
sshKey.pubKeyBase64 = resultArray[3]
};
sshInstance.addKey(sshKey);
};
sshInstance.addKey(sshKey)
}
/**
* checks if not undefined
*/
let notUndefined = (stringArg:string) => {
return (stringArg && stringArg != "undefined" && stringArg != "##");
}
let notUndefined = (stringArg: string) => {
return (stringArg && stringArg !== 'undefined' && stringArg !== '##')
}