npmci/dist/mod_ssh/index.js

71 lines
5.5 KiB
JavaScript
Raw Normal View History

2016-06-23 20:22:03 +00:00
"use strict";
2017-03-11 00:10:37 +00:00
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
2017-06-15 13:46:08 +00:00
const plugins = require("./mod.plugins");
2016-07-18 14:56:53 +00:00
let sshInstance;
2017-08-27 13:24:17 +00:00
exports.handleCli = (argvArg) => __awaiter(this, void 0, void 0, function* () {
if (argvArg._.length >= 2) {
let action = argvArg._[1];
switch (action) {
case 'prepare':
yield exports.prepare();
break;
default:
plugins.beautylog.error(`action >>${action}<< not supported`);
process.exit(1);
2017-08-27 13:24:17 +00:00
}
}
else {
plugins.beautylog.error(`>>npmci ssh ...<< please specify an action!`);
process.exit(1);
}
2017-08-27 13:24:17 +00:00
});
2017-05-19 10:09:33 +00:00
/**
* checks if not undefined
*/
let notUndefined = (stringArg) => {
return (stringArg && stringArg !== 'undefined' && stringArg !== '##');
};
/**
* checks for ENV vars in form of NPMCI_SSHKEY_* and deploys any found ones
*/
2017-08-27 13:24:17 +00:00
exports.prepare = () => __awaiter(this, void 0, void 0, function* () {
sshInstance = new plugins.smartssh.SshInstance(); // init ssh instance
2016-11-24 22:21:40 +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 {
2016-11-24 22:21:40 +00:00
plugins.beautylog.log('In test mode, so not storing SSH keys to disk!');
2016-06-26 00:17:17 +00:00
}
2017-03-11 00:10:37 +00:00
});
/**
* gets called for each found SSH ENV Var and deploys it
*/
2017-03-11 00:10:37 +00:00
let evaluateSshEnv = (sshkeyEnvVarArg) => __awaiter(this, void 0, void 0, function* () {
2017-08-27 13:24:17 +00:00
let sshEnvArray = sshkeyEnvVarArg.split('|');
2016-07-18 14:56:53 +00:00
let sshKey = new plugins.smartssh.SshKey();
2017-08-27 13:24:17 +00:00
plugins.beautylog.info('Found SSH identity for ' + sshEnvArray[1]);
if (notUndefined(sshEnvArray[0])) {
2016-11-24 22:21:40 +00:00
plugins.beautylog.log('---> host defined!');
2017-08-27 13:24:17 +00:00
sshKey.host = sshEnvArray[0];
2016-06-26 00:17:17 +00:00
}
2017-08-27 13:24:17 +00:00
if (notUndefined(sshEnvArray[1])) {
2016-11-24 22:21:40 +00:00
plugins.beautylog.log('---> privKey defined!');
2017-08-27 13:24:17 +00:00
sshKey.privKeyBase64 = sshEnvArray[1];
2016-06-26 00:17:17 +00:00
}
2017-08-27 13:24:17 +00:00
if (notUndefined(sshEnvArray[2])) {
2017-06-15 13:46:08 +00:00
plugins.beautylog.log('---> pubKey defined!');
2017-08-27 13:24:17 +00:00
sshKey.pubKeyBase64 = sshEnvArray[2];
2016-06-26 00:17:17 +00:00
}
2016-06-24 00:54:55 +00:00
sshInstance.addKey(sshKey);
2017-03-11 00:10:37 +00:00
return;
});
2017-10-09 16:10:01 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi90cy9tb2Rfc3NoL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFBQSx5Q0FBd0M7QUFDeEMsSUFBSSxXQUF5QyxDQUFBO0FBRWxDLFFBQUEsU0FBUyxHQUFHLENBQU8sT0FBTyxFQUFFLEVBQUU7SUFDdkMsRUFBRSxDQUFDLENBQUMsT0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