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 });
|
2016-07-18 14:56:53 +00:00
|
|
|
const plugins = require("./npmci.plugins");
|
|
|
|
let sshRegex = /^(.*)\|(.*)\|(.*)/;
|
|
|
|
let sshInstance;
|
2016-09-04 11:42:22 +00:00
|
|
|
/**
|
|
|
|
* checks for ENV vars in form of NPMCI_SSHKEY_* and deploys any found ones
|
|
|
|
*/
|
2017-03-11 00:10:37 +00:00
|
|
|
exports.ssh = () => __awaiter(this, void 0, void 0, function* () {
|
2016-09-04 11:42:22 +00:00
|
|
|
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
|
|
|
});
|
2016-09-04 11:42:22 +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* () {
|
2016-07-18 14:56:53 +00:00
|
|
|
let resultArray = sshRegex.exec(sshkeyEnvVarArg);
|
|
|
|
let sshKey = new plugins.smartssh.SshKey();
|
2016-11-24 22:21:40 +00:00
|
|
|
plugins.beautylog.info('Found SSH identity for ' + resultArray[1]);
|
2016-06-26 00:17:17 +00:00
|
|
|
if (notUndefined(resultArray[1])) {
|
2016-11-24 22:21:40 +00:00
|
|
|
plugins.beautylog.log('---> host defined!');
|
2016-06-24 00:54:55 +00:00
|
|
|
sshKey.host = resultArray[1];
|
2016-06-26 00:17:17 +00:00
|
|
|
}
|
|
|
|
if (notUndefined(resultArray[2])) {
|
2016-11-24 22:21:40 +00:00
|
|
|
plugins.beautylog.log('---> privKey defined!');
|
2016-06-25 16:53:35 +00:00
|
|
|
sshKey.privKeyBase64 = resultArray[2];
|
2016-06-26 00:17:17 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
if (notUndefined(resultArray[3])) {
|
2016-11-24 22:21:40 +00:00
|
|
|
'---> pubKey defined!';
|
2016-06-25 16:53:35 +00:00
|
|
|
sshKey.pubKeyBase64 = resultArray[3];
|
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;
|
|
|
|
});
|
2016-09-04 11:42:22 +00:00
|
|
|
/**
|
|
|
|
* checks if not undefined
|
|
|
|
*/
|
2016-07-18 14:56:53 +00:00
|
|
|
let notUndefined = (stringArg) => {
|
2016-11-24 22:21:40 +00:00
|
|
|
return (stringArg && stringArg !== 'undefined' && stringArg !== '##');
|
2016-06-25 16:53:35 +00:00
|
|
|
};
|
2017-03-11 00:10:37 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtY2kuc3NoLmp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