npmci/dist/mod_ssh/index.js

66 lines
5.1 KiB
JavaScript

"use strict";
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 });
const plugins = require("./mod.plugins");
let sshInstance;
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`);
}
}
});
/**
* 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
*/
exports.prepare = () => __awaiter(this, void 0, void 0, function* () {
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!');
}
});
/**
* gets called for each found SSH ENV Var and deploys it
*/
let evaluateSshEnv = (sshkeyEnvVarArg) => __awaiter(this, void 0, void 0, function* () {
let sshEnvArray = sshkeyEnvVarArg.split('|');
let sshKey = new plugins.smartssh.SshKey();
plugins.beautylog.info('Found SSH identity for ' + sshEnvArray[1]);
if (notUndefined(sshEnvArray[0])) {
plugins.beautylog.log('---> host defined!');
sshKey.host = sshEnvArray[0];
}
if (notUndefined(sshEnvArray[1])) {
plugins.beautylog.log('---> privKey defined!');
sshKey.privKeyBase64 = sshEnvArray[1];
}
if (notUndefined(sshEnvArray[2])) {
plugins.beautylog.log('---> pubKey defined!');
sshKey.pubKeyBase64 = sshEnvArray[2];
}
sshInstance.addKey(sshKey);
return;
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi90cy9tb2Rfc3NoL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFBQSx5Q0FBd0M7QUFDeEMsSUFBSSxXQUF5QyxDQUFBO0FBRWxDLFFBQUEsU0FBUyxHQUFHLENBQU8sT0FBTztJQUNuQyxFQUFFLENBQUMsQ0FBQyxPQUFPLENBQUMsQ0FBQyxDQUFDLE1BQU0sSUFBSSxDQUFDLENBQUMsQ0FBQyxDQUFDO1FBQzFCLElBQUksTUFBTSxHQUFXLE9BQU8sQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUE7UUFDakMsTUFBTSxDQUFDLENBQUMsTUFBTSxDQUFDLENBQUMsQ0FBQztZQUNmLEtBQUssU0FBUztnQkFDWixNQUFNLGVBQU8sRUFBRSxDQUFBO2dCQUNmLEtBQUssQ0FBQTtZQUNQO2dCQUNFLE9BQU8sQ0FBQyxTQUFTLENBQUMsS0FBSyxDQUFDLFlBQVksTUFBTSxrQkFBa0IsQ0FBQyxDQUFBO1FBQ2pFLENBQUM7SUFDSCxDQUFDO0FBQ0gsQ0FBQyxDQUFBLENBQUE7QUFFRDs7R0FFRztBQUNILElBQUksWUFBWSxHQUFHLENBQUMsU0FBaUI7SUFDbkMsTUFBTSxDQUFDLENBQUMsU0FBUyxJQUFJLFNBQVMsS0FBSyxXQUFXLElBQUksU0FBUyxLQUFLLElBQUksQ0FBQyxDQUFBO0FBQ3ZFLENBQUMsQ0FBQTtBQUVEOztHQUVHO0FBQ1EsUUFBQSxPQUFPLEdBQUc7SUFDbkIsV0FBVyxHQUFHLElBQUksT0FBT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