npmci/dist/npmci.ssh.js

52 lines
3.8 KiB
JavaScript
Raw Permalink Normal View History

2016-06-23 20:22:03 +00:00
"use strict";
require("typings-global");
2016-07-18 14:56:53 +00:00
const plugins = require("./npmci.plugins");
let sshRegex = /^(.*)\|(.*)\|(.*)/;
let sshInstance;
/**
* checks for ENV vars in form of NPMCI_SSHKEY_* and deploys any found ones
*/
2016-07-18 14:56:53 +00:00
exports.ssh = () => {
let done = plugins.q.defer();
sshInstance = new plugins.smartssh.SshInstance(); // init ssh instance
2016-06-25 14:29:06 +00:00
plugins.smartparam.forEachMinimatch(process.env, "NPMCI_SSHKEY_*", evaluateSshEnv);
2016-06-26 00:17:17 +00:00
if (!process.env.NPMTS_TEST) {
sshInstance.writeToDisk();
}
else {
plugins.beautylog.log("In test mode, so not storing SSH keys to disk!");
}
;
2016-06-25 14:29:06 +00:00
done.resolve();
return done.promise;
2016-06-23 20:22:03 +00:00
};
/**
* gets called for each found SSH ENV Var and deploys it
*/
2016-07-18 14:56:53 +00:00
let evaluateSshEnv = (sshkeyEnvVarArg) => {
let resultArray = sshRegex.exec(sshkeyEnvVarArg);
let sshKey = new plugins.smartssh.SshKey();
2016-06-26 00:17:17 +00:00
plugins.beautylog.info("Found SSH identity for " + resultArray[1]);
if (notUndefined(resultArray[1])) {
plugins.beautylog.log("---> host defined!");
2016-06-24 00:54:55 +00:00
sshKey.host = resultArray[1];
2016-06-26 00:17:17 +00:00
}
if (notUndefined(resultArray[2])) {
plugins.beautylog.log("---> privKey defined!");
2016-06-25 16:53:35 +00:00
sshKey.privKeyBase64 = resultArray[2];
2016-06-26 00:17:17 +00:00
}
;
if (notUndefined(resultArray[3])) {
"---> pubKey defined!";
2016-06-25 16:53:35 +00:00
sshKey.pubKeyBase64 = resultArray[3];
2016-06-26 00:17:17 +00:00
}
;
2016-06-24 00:54:55 +00:00
sshInstance.addKey(sshKey);
2016-06-23 20:22:03 +00:00
};
/**
* checks if not undefined
*/
2016-07-18 14:56:53 +00:00
let notUndefined = (stringArg) => {
2016-06-25 16:53:35 +00:00
return (stringArg && stringArg != "undefined" && stringArg != "##");
};
2016-09-20 10:43:37 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtY2kuc3NoLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvbnBtY2kuc3NoLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwwQkFBd0I7QUFDeEIsMkNBQTJDO0FBRTNDLElBQUksUUFBUSxHQUFHLG1CQUFtQixDQUFBO0FBQ2xDLElBQUksV0FBd0MsQ0FBQztBQUU3Qzs7R0FFRztBQUNRLFFBQUEsR0FBRyxHQUFHO0lBQ2IsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUM3QixXQUFXLEdBQUcsSUFBSSxPQUFPLENBQUMsUUFBUSxDQUFDLFdBQVcsRUFBRSxDQUFDLENBQUMsb0JBQW9CO0lBQ3RFLE9BQU8sQ0FBQyxVQUFVLENBQUMsZ0JBQWdCLENBQUMsT0FBTyxDQUFDLEdBQUcsRUFBQyxnQkFBZ0IsRUFBQyxjQUFjLENBQUMsQ0FBQztJQUNqRixFQUFFLENBQUEsQ0FBQyxDQUFDLE9BQU8sQ0FBQyxHQUFHLENBQUMsVUFBVSxDQUFDLENBQUEsQ0FBQztRQUN4QixXQUFXLENBQUMsV0FBVyxFQUFFLENBQUM7SUFDOUIsQ0FBQztJQUFDLElBQUksQ0FBQyxDQUFDO1FBQ0osT0FBTyxDQUFDLFNBQVMsQ0FBQyxHQUFHLENBQUMsZ0RBQWdELENBQUMsQ0FBQztJQUM1RSxDQUFDO0lBQUEsQ0FBQztJQUNGLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQztJQUNmLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDO0FBQ3hCLENBQUMsQ0FBQ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