npmci/dist/npmci.ssh.js
2016-06-26 02:17:17 +02:00

45 lines
5.4 KiB
JavaScript

"use strict";
require("typings-global");
var plugins = require("./npmci.plugins");
var sshRegex = /^(.*)\|(.*)\|(.*)/;
var sshInstance;
exports.ssh = function () {
var done = plugins.q.defer();
sshInstance = new plugins.smartssh.SshInstance();
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;
};
var evaluateSshEnv = function (sshkeyEnvVarArg) {
var resultArray = sshRegex.exec(sshkeyEnvVarArg);
var 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);
};
var notUndefined = function (stringArg) {
return (stringArg && stringArg != "undefined" && stringArg != "##");
};
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5wbWNpLnNzaC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBQ3hCLElBQVksT0FBTyxXQUFNLGlCQUFpQixDQUFDLENBQUE7QUFFM0MsSUFBSSxRQUFRLEdBQUcsbUJBQW1CLENBQUE7QUFDbEMsSUFBSSxXQUF3QyxDQUFDO0FBRWxDLFdBQUcsR0FBRztJQUNiLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUM7SUFDN0IsV0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