npmci/dist/npmci.ssh.js
2016-09-20 12:43:37 +02:00

52 lines
3.8 KiB
JavaScript

"use strict";
require("typings-global");
const plugins = require("./npmci.plugins");
let sshRegex = /^(.*)\|(.*)\|(.*)/;
let sshInstance;
/**
* checks for ENV vars in form of NPMCI_SSHKEY_* and deploys any found ones
*/
exports.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();
}
else {
plugins.beautylog.log("In test mode, so not storing SSH keys to disk!");
}
;
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];
}
if (notUndefined(resultArray[2])) {
plugins.beautylog.log("---> privKey defined!");
sshKey.privKeyBase64 = resultArray[2];
}
;
if (notUndefined(resultArray[3])) {
"---> pubKey defined!";
sshKey.pubKeyBase64 = resultArray[3];
}
;
sshInstance.addKey(sshKey);
};
/**
* checks if not undefined
*/
let notUndefined = (stringArg) => {
return (stringArg && stringArg != "undefined" && stringArg != "##");
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtY2kuc3NoLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvbnBtY2kuc3NoLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwwQkFBd0I7QUFDeEIsMkNBQTJDO0FBRTNDLElBQUksUUFBUSxHQUFHLG1CQUFtQixDQUFBO0FBQ2xDLElBQUksV0FBd0MsQ0FBQztBQUU3Qzs7R0FFRztB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