npmci/dist/npmci.ssh.js

30 lines
3.9 KiB
JavaScript
Raw Permalink Normal View History

2016-06-23 20:22:03 +00:00
"use strict";
require("typings-global");
var plugins = require("./npmci.plugins");
2016-06-25 16:53:35 +00:00
var sshRegex = /^(.*)\|(.*)\|(.*)/;
2016-06-24 00:54:55 +00:00
var sshInstance;
2016-06-23 20:22:03 +00:00
exports.ssh = function () {
2016-06-25 14:29:06 +00:00
var done = plugins.q.defer();
2016-06-24 00:54:55 +00:00
sshInstance = new plugins.smartssh.SshInstance();
2016-06-25 14:29:06 +00:00
plugins.smartparam.forEachMinimatch(process.env, "NPMCI_SSHKEY_*", evaluateSshEnv);
2016-06-25 00:55:36 +00:00
sshInstance.writeToDisk();
2016-06-25 14:29:06 +00:00
done.resolve();
return done.promise;
2016-06-23 20:22:03 +00:00
};
2016-06-25 14:29:06 +00:00
var evaluateSshEnv = function (sshkeyEnvVarArg) {
2016-06-24 00:54:55 +00:00
var resultArray = sshRegex.exec(sshkeyEnvVarArg);
var sshKey = new plugins.smartssh.SshKey();
2016-06-25 16:53:35 +00:00
if (notUndefined(resultArray[1]))
2016-06-24 00:54:55 +00:00
sshKey.host = resultArray[1];
2016-06-25 16:53:35 +00:00
if (notUndefined(resultArray[2]))
sshKey.privKeyBase64 = resultArray[2];
if (notUndefined(resultArray[3]))
sshKey.pubKeyBase64 = resultArray[3];
2016-06-24 00:54:55 +00:00
sshInstance.addKey(sshKey);
2016-06-23 20:22:03 +00:00
};
2016-06-25 16:53:35 +00:00
var notUndefined = function (stringArg) {
return (stringArg && stringArg != "undefined" && stringArg != "##");
};
2016-06-23 20:22:03 +00:00
2016-06-25 16:53:35 +00:00
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5wbWNpLnNzaC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBQ3hCLElBQVksT0FBTy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