UNPKG

@axway/axway-central-cli

Version:

Manage APIs, services and publish to the Amplify Marketplace

227 lines (217 loc) 11.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.testables = exports.gatewayConnectivity = exports.completeInstall = exports.askConfigType = exports.askBundleType = exports.SensediaInstallMethods = 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")); 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)('engage: install: agents: sensedia'); const daImage = `${_types.PublicDockerRepoBaseUrl}${_types.BasePaths.DockerAgentPublicRepo}/${_types.AgentNames.SENSEDIA_DA}`; const taImage = `${_types.PublicDockerRepoBaseUrl}${_types.BasePaths.DockerAgentPublicRepo}/${_types.AgentNames.SENSEDIA_TA}`; // 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}`, SensediaDABinaryFile: 'discovery_agent', SensediaDAYaml: 'discovery_agent.yml', SensediaTABinaryFile: 'traceability_agent', SensediaTAYaml: 'traceability_agent.yml' }; // SensediaPrompts - prompts for user inputs const SensediaPrompts = { configTypeMsg: 'Select the mode of installation', enterBaseUrl: 'Enter the Sensedia Base URL', selectAuthMethod: 'Select the authentication method', enterClientId: 'Enter the Sensedia Client ID', enterClientSecret: 'Enter the Sensedia Client Secret', enterAuthToken: 'Enter the Sensedia Authentication Token', enterDeveloperEmail: 'Enter the Developer Email', enterEnvironments: 'Do you want to configure specific environments for discovery and reporting? If no value is provided, discovery occurs on all the environments', enterMoreEnvironments: 'Enter an environment name (or press Enter to finish)', invalidEnvironmentMessage: 'Commas are not allowed in the name due to the way the agent parses the environments list. Make sure you input one environment name at a time' }; const askBundleType = async gateway => { console.log(gateway); if (gateway === _types.GatewayTypes.SENSEDIA) { return await (0, _basicPrompts.askList)({ msg: helpers.agentMessages.selectAgentType, choices: [_types.BundleType.ALL_AGENTS, _types.BundleType.DISCOVERY] }); } else { return _types.BundleType.DISCOVERY; } }; exports.askBundleType = askBundleType; const askConfigType = async () => { return _types.AgentConfigTypes.DOCKERIZED; }; // // Questions for the configuration of Sensedia agents // exports.askConfigType = askConfigType; const askSensediaBaseUrl = async () => await (0, _basicPrompts.askInput)({ msg: SensediaPrompts.enterBaseUrl, validate: (0, _basicPrompts.validateRegex)(helpers.SensediaRegexPatterns.urlRegex, helpers.invalidValueExampleErrMsg('baseURL', 'https://sensedia.com')) }); const askSensediaAuthMethod = async () => await (0, _basicPrompts.askList)({ msg: SensediaPrompts.selectAuthMethod, choices: [{ name: helpers.SensediaAuthType.OAuth, value: helpers.SensediaAuthType.OAuth }, { name: helpers.SensediaAuthType.StaticToken, value: helpers.SensediaAuthType.StaticToken }] }); const askSensediaClientId = async () => await (0, _basicPrompts.askInput)({ msg: SensediaPrompts.enterClientId }); const askSensediaClientSecret = async () => await (0, _basicPrompts.askInput)({ msg: SensediaPrompts.enterClientSecret }); const askSensediaAuthToken = async () => await (0, _basicPrompts.askInput)({ msg: SensediaPrompts.enterAuthToken }); const askSensediaDeveloperEmail = async () => await (0, _basicPrompts.askInput)({ msg: SensediaPrompts.enterDeveloperEmail, validate: (0, _basicPrompts.validateRegex)(helpers.SensediaRegexPatterns.emailRegex, helpers.invalidValueExampleErrMsg('DeveloperEmail', 'dev@gmail.com')) }); const askSensediaEnvironments = async () => { let environments = []; let addEnvironments = (await (0, _basicPrompts.askList)({ msg: SensediaPrompts.enterEnvironments, default: _types.YesNo.No, choices: _types.YesNoChoices })) === _types.YesNo.Yes; while (addEnvironments) { const env = await (0, _basicPrompts.askInput)({ msg: SensediaPrompts.enterMoreEnvironments, validate: (0, _basicPrompts.validateRegex)(helpers.SensediaRegexPatterns.noCommaRegex, SensediaPrompts.invalidEnvironmentMessage), allowEmptyInput: true }); if (env && env.trim() !== '') { environments.push(env); } else { return environments; } } return environments; }; const gatewayConnectivity = async installConfig => { const SensediaAgentValues = new helpers.SensediaAgentValues(); console.log('\nCONNECTION TO Sensedia:'); console.log(_chalk.default.gray(`The discovery agent needs to connect to the Sensedia to discover API's for publishing to Amplify.\nThe traceability agent needs to connect to an Sensedia for collecting APIs transactions. These will be forwarded to the Business Insights.\n`)); // Sensedia Discovery Agent Prompts if (installConfig.switches.isDaEnabled) { console.log(_chalk.default.gray(`\nDiscovery Agent Configuration\nThe discovery agent needs to connect to Sensedia.`)); await askDiscoveryPrompts(SensediaAgentValues); } return SensediaAgentValues; }; 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.SENSEDIA}`)); }; const dockerSuccessMsg = installConfig => { let dockerInfo; const runDaLinuxMsg = `docker run -it --env-file ${helpers.pwd}/${helpers.configFiles.DA_ENV_VARS} -v ${helpers.pwd}:/keys ${helpers.eolChar}`; const runDaWinMsg = `docker run -it --env-file ${helpers.pwdWin}/${helpers.configFiles.DA_ENV_VARS} -v ${helpers.pwdWin}:/keys ${helpers.eolCharWin}`; const runTaLinuxMsg = `docker run -it --env-file ${helpers.pwd}/${helpers.configFiles.TA_ENV_VARS} -v ${helpers.pwd}:/keys ${helpers.eolChar}`; const runTaWinMsg = `docker run -it --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 ${taImageVersion}`), '\n'); } }; // Sensedia DA prompts async function askDiscoveryPrompts(sensediaAgentValues) { // Sensedia Base URL sensediaAgentValues.baseUrl = await askSensediaBaseUrl(); // Sensedia Authentication Method sensediaAgentValues.authType = await askSensediaAuthMethod(); if (sensediaAgentValues.authType === helpers.SensediaAuthType.OAuth) { // OAuth authentication sensediaAgentValues.clientId = await askSensediaClientId(); sensediaAgentValues.clientSecret = await askSensediaClientSecret(); } else { // Static token authentication sensediaAgentValues.authToken = await askSensediaAuthToken(); } // Sensedia Developer Email sensediaAgentValues.developerEmail = await askSensediaDeveloperEmail(); // Sensedia Environments sensediaAgentValues.environments = [...new Set(await askSensediaEnvironments())]; } const completeInstall = async installConfig => { /** * Create agent resources */ const sensediaAgentValues = installConfig.gatewayConfig; // Add final settings to SensediaAgentsValues sensediaAgentValues.centralConfig = installConfig.centralConfig; sensediaAgentValues.traceabilityConfig = installConfig.traceabilityConfig; console.log('Generating the configuration file(s)...'); if (installConfig.switches.isDaEnabled) { (0, _utils.writeTemplates)(ConfigFiles.DAEnvVars, sensediaAgentValues, helpers.sensediaDAEnvVarTemplate); } if (installConfig.switches.isTaEnabled) { (0, _utils.writeTemplates)(ConfigFiles.TAEnvVars, sensediaAgentValues, helpers.sensediaTAEnvVarTemplate); } console.log('Configuration file(s) have been successfully created.\n'); generateSuccessHelpMsg(installConfig); }; exports.completeInstall = completeInstall; const SensediaInstallMethods = exports.SensediaInstallMethods = { GetBundleType: askBundleType, GetDeploymentType: askConfigType, AskGatewayQuestions: gatewayConnectivity, FinalizeGatewayInstall: completeInstall, ConfigFiles: Object.values(ConfigFiles), AgentNameMap: { [_types.AgentTypes.da]: _types.AgentNames.SENSEDIA_DA, [_types.AgentTypes.ta]: _types.AgentNames.SENSEDIA_TA }, GatewayDisplay: _types.GatewayTypes.SENSEDIA }; const testables = exports.testables = { SensediaPrompts, ConfigFiles };