71 lines
5.5 KiB
JavaScript
71 lines
5.5 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`);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
else {
|
|
plugins.beautylog.error(`>>npmci ssh ...<< please specify an action!`);
|
|
process.exit(1);
|
|
}
|
|
});
|
|
/**
|
|
* 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi90cy9tb2Rfc3NoL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFBQSx5Q0FBeUM7QUFDekMsSUFBSSxXQUF5QyxDQUFDO0FBRW5DLFFBQUEsU0FBUyxHQUFHLENBQU0sT0FBTyxFQUFDLEVBQUU7SUFDckMsRUFBRSxDQUFDLENBQUMsT0FBTyxDQUFDLENBQUMsQ0FBQyxNQUFNLElBQUksQ0FBQyxDQUFDLENBQUMsQ0FBQztRQUMxQixJQUFJLE1BQU0sR0FBVyxPQUFPLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDO1FBQ2xDLE1BQU0sQ0FBQyxDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUM7WUFDZixLQUFLLFNBQVM7Z0JBQ1osTUFBTSxlQUFPLEVBQUUsQ0FBQztnQkFDaEIsS0FBSyxDQUFDO1lBQ1I7Z0JBQ0UsT0FBTyxDQUFDLFNBQVM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