@axway/axway-central-cli
Version:
Manage APIs, services and publish to the Amplify Marketplace
164 lines (159 loc) • 9.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.testables = exports.gatewayConnectivity = exports.defaultLogFiles = exports.completeInstall = exports.askConfigType = exports.askBundleType = exports.WSO2InstallMethods = exports.ConfigFiles = void 0;
var _chalk = _interopRequireDefault(require("chalk"));
var _snooplogg = _interopRequireDefault(require("snooplogg"));
var _basicPrompts = require("../../common/basicPrompts");
var _types = require("../../common/types");
var _utils = require("../../common/utils");
var _agents = require("./agents");
var helpers = _interopRequireWildcard(require("./helpers"));
var _wso2Templates = require("./helpers/templates/wso2Templates");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
// @ts-ignore
const {
log
} = (0, _snooplogg.default)('central: install: agents: WSO2');
const daImage = `${_types.PublicDockerRepoBaseUrl}${_types.BasePaths.DockerAgentPublicRepo}/${_types.AgentNames.WSO2_DA}`;
const taImage = `${_types.PublicDockerRepoBaseUrl}${_types.BasePaths.DockerAgentPublicRepo}/${_types.AgentNames.WSO2_TA}`;
const defaultLogFiles = exports.defaultLogFiles = '/group-*_instance-*.log';
// ConfigFiles - all the config file that are used in the setup
const ConfigFiles = exports.ConfigFiles = {
DAEnvVars: `${helpers.configFiles.DA_ENV_VARS}`,
TAEnvVars: `${helpers.configFiles.TA_ENV_VARS}`,
WSO2DABinaryFile: 'discovery_agent',
WSO2DAYaml: 'discovery_agent.yml',
WSO2TABinaryFile: 'traceability_agent',
WSO2TAYaml: 'traceability_agent.yml'
};
// WSO2Prompts - prompts for user inputs
const WSO2Prompts = {
configTypeMsg: 'Select the mode of installation',
enterWSO2BaseURL: 'Enter the WSO2 baseURL',
enterWSO2ClientID: 'Enter the WSO2 ClientID',
enterWSO2ClientSecret: 'Enter the WSO2 ClientSecret'
};
const askBundleType = async () => {
return await (0, _basicPrompts.askList)({
msg: helpers.agentMessages.selectAgentType,
choices: [_types.BundleType.ALL_AGENTS, _types.BundleType.DISCOVERY, _types.BundleType.TRACEABILITY]
});
};
exports.askBundleType = askBundleType;
const askConfigType = async () => {
return _types.AgentConfigTypes.DOCKERIZED;
};
//
// Questions for the configuration of WSO2 agents
//
exports.askConfigType = askConfigType;
const askWSO2BaseURL = async () => await (0, _basicPrompts.askInput)({
msg: WSO2Prompts.enterWSO2BaseURL,
allowEmptyInput: false,
validate: (0, _basicPrompts.validateRegex)(helpers.WSO2RegexPatterns.wso2BaseURLRegex, helpers.invalidValueExampleErrMsg('WSO2_BASEURL', 'https://www.wso2domain.com'))
});
const askWSO2ClientID = async () => await (0, _basicPrompts.askInput)({
msg: WSO2Prompts.enterWSO2ClientID
});
const askWSO2ClientSecret = async () => await (0, _basicPrompts.askInput)({
msg: WSO2Prompts.enterWSO2ClientSecret
});
const gatewayConnectivity = async installConfig => {
const agentValues = new _wso2Templates.WSO2AgentValues();
console.log('\nCONNECTION TO WSO2:');
console.log(_chalk.default.gray(`The discovery agent needs to connect to the WSO2 API Manager to discover API's for publishing to Amplify.\nThe traceability agent will serve as the trace logging service that will receive WSO2 tracing payloads. These will be forwarded to the Business Insights. There are no specific WSO2 Traceability agent variables.\n`));
if (installConfig.switches.isDaEnabled) {
console.log(_chalk.default.gray(`\nDiscovery Agent Configuration\n`));
await askDiscoveryPrompts(agentValues);
}
return agentValues;
};
exports.gatewayConnectivity = gatewayConnectivity;
const generateSuccessHelpMsg = installConfig => {
if (installConfig.centralConfig.ampcDosaInfo.isNew && !installConfig.switches.isHelmInstall) {
console.log(_chalk.default.yellow(_agents.svcAccMsg));
}
dockerSuccessMsg(installConfig);
console.log(_chalk.default.gray(`\nAdditional information about agent features can be found here:\n${helpers.agentsDocsUrl.WSO2}`));
};
const dockerSuccessMsg = installConfig => {
let dockerInfo;
const runDaLinuxMsg = `docker run --env-file ${helpers.pwd}/${helpers.configFiles.DA_ENV_VARS} -v ${helpers.pwd}:/keys ${helpers.eolChar}`;
const runDaWinMsg = `docker run --env-file ${helpers.pwdWin}/${helpers.configFiles.DA_ENV_VARS} -v ${helpers.pwdWin}:/keys ${helpers.eolCharWin}`;
const runTaLinuxMsg = `docker run --env-file ${helpers.pwd}/${helpers.configFiles.TA_ENV_VARS} -v ${helpers.pwd}:/keys ${helpers.eolChar}`;
const runTaWinMsg = `docker run --env-file ${helpers.pwdWin}/${helpers.configFiles.TA_ENV_VARS} -v ${helpers.pwdWin}:/keys ${helpers.eolCharWin}`;
const startDaLinuxMsg = `\nStart the Discovery Agent on a Linux based machine`;
const startDaWinMsg = `\nStart the Discovery Agent on a Windows machine`;
const startTaLinuxMsg = `\nStart the Traceability Agent on a Linux based machine`;
const startTaWinMsg = `\nStart the Traceability Agent on a Windows machine`;
if (installConfig.switches.isDaEnabled && installConfig.switches.isTaEnabled) {
dockerInfo = `To utilize the agents, pull the latest Docker images and run them using the appropriate supplied environment files, (${helpers.configFiles.DA_ENV_VARS} & ${helpers.configFiles.TA_ENV_VARS}):`;
} else if (installConfig.switches.isDaEnabled) {
dockerInfo = `To utilize the discovery agent, pull the latest Docker image and run it using the supplied environment file, (${helpers.configFiles.DA_ENV_VARS}):`;
} else {
dockerInfo = `To utilize the traceability agent, pull the latest Docker image and run it using the supplied environment file, (${helpers.configFiles.TA_ENV_VARS}):`;
}
console.log(_chalk.default.whiteBright(dockerInfo), '\n');
if (installConfig.switches.isDaEnabled) {
const daImageVersion = `${daImage}:${installConfig.daVersion}`;
console.log(_chalk.default.white('Pull the latest image of the Discovery Agent:'));
console.log(_chalk.default.cyan(`docker pull ${daImageVersion}`));
console.log(_chalk.default.white(_utils.isWindows ? startDaWinMsg : startDaLinuxMsg));
console.log(_chalk.default.cyan(_utils.isWindows ? runDaWinMsg : runDaLinuxMsg));
console.log('\t', _chalk.default.cyan(`-v /data ${daImageVersion}`), '\n');
}
if (installConfig.switches.isTaEnabled) {
const taImageVersion = `${taImage}:${installConfig.taVersion}`;
console.log(_chalk.default.white('Pull the latest image of the Traceability Agent:'));
console.log(_chalk.default.cyan(`docker pull ${taImageVersion}`));
console.log(_chalk.default.white(_utils.isWindows ? startTaWinMsg : startTaLinuxMsg));
console.log(_chalk.default.cyan(_utils.isWindows ? runTaWinMsg : runTaLinuxMsg));
console.log('\t', _chalk.default.cyan(`-v /data -p 8888:8888 ${helpers.eolChar}`));
console.log('\t', _chalk.default.cyan(`${taImageVersion}`), '\n');
console.log(_chalk.default.white('Configure WSO2 to connect to localhost:8888.'));
}
};
async function askDiscoveryPrompts(agentValues) {
agentValues.wso2BaseURL = await askWSO2BaseURL();
agentValues.wso2ClientID = await askWSO2ClientID();
agentValues.wso2ClientSecret = await askWSO2ClientSecret();
}
const completeInstall = async installConfig => {
/**
* Create agent resources
*/
const agentValues = installConfig.gatewayConfig;
// Add final settings to WSO2 agentValues
agentValues.centralConfig = installConfig.centralConfig;
agentValues.traceabilityConfig = installConfig.traceabilityConfig;
console.log('Generating the configuration file(s)...');
if (installConfig.switches.isDaEnabled) {
(0, _utils.writeTemplates)(ConfigFiles.DAEnvVars, agentValues, _wso2Templates.wso2DAEnvVarTemplate);
}
if (installConfig.switches.isTaEnabled) {
(0, _utils.writeTemplates)(ConfigFiles.TAEnvVars, agentValues, _wso2Templates.wso2TAEnvVarTemplate);
}
console.log('Configuration file(s) have been successfully created.\n');
generateSuccessHelpMsg(installConfig);
};
exports.completeInstall = completeInstall;
const WSO2InstallMethods = exports.WSO2InstallMethods = {
GetBundleType: askBundleType,
GetDeploymentType: askConfigType,
AskGatewayQuestions: gatewayConnectivity,
FinalizeGatewayInstall: completeInstall,
ConfigFiles: Object.values(ConfigFiles),
AgentNameMap: {
[_types.AgentTypes.da]: _types.AgentNames.WSO2_DA,
[_types.AgentTypes.ta]: _types.AgentNames.WSO2_TA
},
GatewayDisplay: _types.GatewayTypes.WSO2
};
const testables = exports.testables = {
WSO2Prompts,
ConfigFiles,
defaultLogFiles
};