UNPKG

@axway/axway-central-cli

Version:

Manage APIs, services and publish to the Amplify Marketplace

299 lines (280 loc) 17.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateFrequency = exports.svcAccMsg = exports.prompts = exports.localhost = exports.agents = void 0; var _chalk = _interopRequireDefault(require("chalk")); var _snooplogg = _interopRequireDefault(require("snooplogg")); var _ApiServerClient = require("../../common/ApiServerClient"); var _basicPrompts = require("../../common/basicPrompts"); var _CoreConfigController = require("../../common/CoreConfigController"); var _DefinitionsManager = require("../../common/DefinitionsManager"); var _PlatformClient = require("../../common/PlatformClient"); var _CliConfigManager = require("../../common/CliConfigManager"); var _Renderer = _interopRequireDefault(require("../../common/Renderer")); var _types = require("../../common/types"); var _utils = require("../../common/utils"); var akamaiAgents = _interopRequireWildcard(require("./akamaiAgents")); var akamaiSaasAgents = _interopRequireWildcard(require("./akamaiSaasAgents")); var apigeeXAgents = _interopRequireWildcard(require("./apigeexAgents")); var awsAgents = _interopRequireWildcard(require("./awsAgents")); var awsSaaSAgents = _interopRequireWildcard(require("./awsSaasAgents")); var gitHubAgents = _interopRequireWildcard(require("./gitHubSaasAgents")); var gitLabAgents = _interopRequireWildcard(require("./gitLabAgents")); var azureAgents = _interopRequireWildcard(require("./azureAgents")); var edgeAgents = _interopRequireWildcard(require("./edgeAgents")); var apigeeSaaSAgents = _interopRequireWildcard(require("./apigeexSaasAgents")); var helpers = _interopRequireWildcard(require("./helpers")); var istioAgents = _interopRequireWildcard(require("./istioAgents")); var azureSaasAgents = _interopRequireWildcard(require("./azureSaasAgents")); var kafkaAgents = _interopRequireWildcard(require("./kafkaAgents")); var swaggerHubAgents = _interopRequireWildcard(require("./swaggerHubSaasAgents")); var graylogAgent = _interopRequireWildcard(require("./graylogAgent")); var ibmAPIConnectAgent = _interopRequireWildcard(require("./ibmAPIConnectAgents")); var softwareAGWebMethodsAgent = _interopRequireWildcard(require("./softwareAGWebMethodsAgents")); var traceableAgent = _interopRequireWildcard(require("./traceableAgents")); var traceableSaaSAgents = _interopRequireWildcard(require("./traceableSaasAgents")); var platform = _interopRequireWildcard(require("./platform")); var backstageAgent = _interopRequireWildcard(require("./backstageAgents")); var sapApiPortalAgent = _interopRequireWildcard(require("./sapApiPortalAgents")); var sensediaAgents = _interopRequireWildcard(require("./sensediaAgents")); var wso2Agents = _interopRequireWildcard(require("./wso2Agents")); 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 }; } const { log } = (0, _snooplogg.default)('engage: install: agents'); const localhost = exports.localhost = 'localhost'; const svcAccMsg = exports.svcAccMsg = '\nPlease make sure to copy the "private_key.pem" and "public_key.pem" files for the existing service account you selected.'; const prompts = exports.prompts = { hostedAgentOption: 'Will this be an embedded agent', selectGatewayType: 'Select the type of gateway you want to connect' }; const agentInstallFlows = { [_types.GatewayTypes.AKAMAI]: akamaiAgents.AkamaiInstallMethods, [_types.GatewayTypes.EDGE_GATEWAY]: edgeAgents.EdgeInstallMethods, [_types.GatewayTypes.EDGE_GATEWAY_ONLY]: edgeAgents.EdgeGWOnlyInstallMethods, [_types.GatewayTypes.AWS_GATEWAY]: awsAgents.AWSInstallMethods, [_types.GatewayTypes.APIGEEX_GATEWAY]: apigeeXAgents.ApigeeXInstallMethods, [_types.GatewayTypes.GITLAB]: gitLabAgents.GitLabInstallMethods, [_types.GatewayTypes.AZURE_GATEWAY]: azureAgents.AzureInstallMethods, [_types.GatewayTypes.AZURE_EVENTHUB]: azureAgents.AzureInstallMethods, [_types.GatewayTypes.ISTIO]: istioAgents.IstioInstallMethods, [_types.GatewayTypes.KAFKA]: kafkaAgents.KafkaInstallMethods, [_types.GatewayTypes.GRAYLOG]: graylogAgent.GraylogInstallMethods, [_types.GatewayTypes.IBMAPICONNECT]: ibmAPIConnectAgent.IBMAPIConnectInstallMethods, [_types.GatewayTypes.SOFTWAREAGWEBMETHODS]: softwareAGWebMethodsAgent.SoftwareAGWebMethodsInstallMethods, [_types.GatewayTypes.TRACEABLE]: traceableAgent.TraceableInstallMethods, [_types.GatewayTypes.BACKSTAGE]: backstageAgent.BackstageInstallMethods, [_types.GatewayTypes.SAPAPIPORTAL]: sapApiPortalAgent.SAPAPIPortalInstallMethods, [_types.GatewayTypes.SENSEDIA]: sensediaAgents.SensediaInstallMethods, [_types.GatewayTypes.WSO2]: wso2Agents.WSO2InstallMethods }; const saasAgentInstallFlows = { [_types.GatewayTypes.AKAMAI]: akamaiSaasAgents.AkamaiSaaSInstallMethods, [_types.SaaSGatewayTypes.AWS_GATEWAY]: awsSaaSAgents.AWSSaaSInstallMethods, [_types.SaaSGatewayTypes.GITHUB]: gitHubAgents.GitHubSaaSInstallMethods, [_types.SaaSGatewayTypes.APIGEEX_GATEWAY]: apigeeSaaSAgents.APIGEEXSaaSInstallMethods, [_types.SaaSGatewayTypes.SWAGGERHUB]: swaggerHubAgents.SwaggerHubSaaSInstallMethods, [_types.GatewayTypes.AZURE_GATEWAY]: azureSaasAgents.AzureSaaSInstallMethods, [_types.GatewayTypes.AZURE_EVENTHUB]: azureSaasAgents.AzureSaaSInstallMethods, [_types.GatewayTypes.TRACEABLE]: traceableSaaSAgents.TraceableSaaSInstallMethods }; const createConfigBackup = async (configFiles, gatewayType) => { // If current configurations exist, back them up const configsExist = await helpers.createBackUpConfigs(configFiles); if (configsExist) { console.log(`\nCreated configuration backups for ${gatewayType}`); } }; const determineRegion = async region => { let configurationRegion = (await (0, _utils.getConfig)())[_CliConfigManager.CliConfigKeys.REGION]; if (region) { return region.toString(); } return configurationRegion ? configurationRegion : _types.Regions.US; }; const agents = exports.agents = { action: async function ({ argv, console }) { const { baseUrl, account, region, apicDeployment, cache, axwayManaged } = argv; let isCmdError = false; const render = new _Renderer.default(console); try { var _accountInfo$roles, _accountInfo$roles2; // initialize clients const apiServerClient = new _ApiServerClient.ApiServerClient({ baseUrl, account, region, useCache: cache }); const platformClient = new _PlatformClient.PlatformClient({ baseUrl, account, region }); const defsManager = await new _DefinitionsManager.DefinitionsManager(apiServerClient).init(); // Verify account has permission to create an environment and service account. const accountInfo = await platformClient.getAccountInfo(); const isCentralAdmin = accountInfo === null || accountInfo === void 0 ? void 0 : (_accountInfo$roles = accountInfo.roles) === null || _accountInfo$roles === void 0 ? void 0 : _accountInfo$roles.includes(_CoreConfigController.AccountRole.ApiCentralAdmin); const isPlatformAdmin = accountInfo === null || accountInfo === void 0 ? void 0 : (_accountInfo$roles2 = accountInfo.roles) === null || _accountInfo$roles2 === void 0 ? void 0 : _accountInfo$roles2.includes(_CoreConfigController.AccountRole.PlatformAdmin); checkUserRole(isCentralAdmin, isPlatformAdmin, accountInfo, render); // helper text console.log(_chalk.default.gray(`This command configures and installs the agents so that you can manage your gateway environment within the Amplify Platform.\n`)); let installConfig = new _types.AgentInstallConfig(); installConfig.centralConfig.apiServerClient = apiServerClient; installConfig.centralConfig.definitionManager = defsManager; installConfig.centralConfig.axwayManaged = !!axwayManaged; let orgRegion = ''; orgRegion = region; // if region cmd arg is not passed in, then consider the region from the account info if (region === undefined) { orgRegion = accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.org.region; } // top priority is region option on command line, second priority is region from config file, default is US installConfig.centralConfig.region = await determineRegion(orgRegion); let gatewayTypeChoices = []; Object.values(_types.GatewayTypes).forEach(v => gatewayTypeChoices.push(v)); Object.values(_types.SaaSGatewayTypes).filter(v => v !== _types.SaaSGatewayTypes.AWS_GATEWAY && v !== _types.SaaSGatewayTypes.APIGEEX_GATEWAY && v !== _types.SaaSGatewayTypes.TRACEABLE && v !== _types.SaaSGatewayTypes.AKAMAI).forEach(v => gatewayTypeChoices.push(v)); let gatewayChoices = gatewayTypeChoices.sort().filter(v => v !== _types.GatewayTypes.EDGE_GATEWAY_ONLY); let gatewayType = await (0, _basicPrompts.askList)({ msg: prompts.selectGatewayType, choices: gatewayChoices }); // Check for central environments if Traceable is selected (before asking about hosted vs on-premise) if (gatewayType === _types.GatewayTypes.TRACEABLE) { const centralEnvs = await helpers.getCentralEnvironments(installConfig.centralConfig.apiServerClient, installConfig.centralConfig.definitionManager); if (!centralEnvs || centralEnvs.length === 0) { console.log(_chalk.default.red('Installation cannot proceed: No Engage environments are available for mapping.')); console.log(_chalk.default.yellow('Please create at least one Engage environment before installing the Traceable agent.')); console.log(_chalk.default.gray('You can create an environment using: axway engage create environment')); process.exit(1); } } // if this check gets bigger, may think about an array of agents that can be both ground and embedded until ground agents become obsolete if (gatewayType === _types.GatewayTypes.AWS_GATEWAY || gatewayType === _types.GatewayTypes.AZURE_GATEWAY || gatewayType === _types.GatewayTypes.AZURE_EVENTHUB || gatewayType === _types.GatewayTypes.APIGEEX_GATEWAY || gatewayType === _types.GatewayTypes.TRACEABLE || gatewayType === _types.GatewayTypes.AKAMAI) { // hosted vs on premise installConfig.switches.isHostedInstall = (await (0, _basicPrompts.askList)({ msg: prompts.hostedAgentOption, choices: _types.YesNoChoices, default: _types.YesNo.Yes })) === _types.YesNo.Yes; } if (gatewayType === _types.SaaSGatewayTypes.GITHUB || gatewayType === _types.SaaSGatewayTypes.SWAGGERHUB) { installConfig.switches.isHostedInstall = true; } // if gateway type is edge ask Gateway only or not if (gatewayType === _types.GatewayTypes.EDGE_GATEWAY) { installConfig.switches.isGatewayOnly = false; gatewayType = await edgeAgents.askIsGatewayOnlyMode(); } installConfig.switches.isGatewayOnly = gatewayType === _types.GatewayTypes.EDGE_GATEWAY_ONLY; installConfig.gatewayType = gatewayType; let agentInstallFlow = agentInstallFlows[installConfig.gatewayType]; if (installConfig.switches.isHostedInstall) { agentInstallFlow = saasAgentInstallFlows[installConfig.gatewayType]; } // Create the object of GatewayTypes -> BundleType functions installConfig.bundleType = await agentInstallFlow.GetBundleType(installConfig.gatewayType); installConfig.switches.isDaEnabled = installConfig.bundleType === _types.BundleType.ALL_AGENTS || installConfig.bundleType === _types.BundleType.DISCOVERY; installConfig.switches.isTaEnabled = installConfig.bundleType === _types.BundleType.ALL_AGENTS || installConfig.bundleType === _types.BundleType.TRACEABILITY || installConfig.bundleType === _types.BundleType.TRACEABILITY_OFFLINE; // Create the object of GatewayTypes -> BundleType functions installConfig.deploymentType = await agentInstallFlow.GetDeploymentType(); installConfig.switches.isHelmInstall = installConfig.deploymentType === _types.AgentConfigTypes.HELM; installConfig.switches.isDockerInstall = installConfig.deploymentType === _types.AgentConfigTypes.DOCKERIZED; installConfig.switches.isBinaryInstall = installConfig.deploymentType === _types.AgentConfigTypes.BINARIES; // Get the version of the agents from jfrog, not needed in hosted install await getAgentVersions(agentInstallFlow, installConfig); // if EDGE_GATEWAY or EDGE_GATEWAY_ONLY and isDaEnabled, ask if the organization structure should replicate if ((gatewayType === _types.GatewayTypes.EDGE_GATEWAY || gatewayType === _types.GatewayTypes.EDGE_GATEWAY_ONLY) && installConfig.switches.isDaEnabled) { installConfig.switches.isOrgRep = await edgeAgents.askOrganizationReplication(); } // get platform connectivity installConfig.centralConfig = await platform.getCentralConfig(apiServerClient, platformClient, defsManager, apicDeployment, installConfig); // Create the object of GatewayTypes -> GatewayConnectivity functions installConfig.gatewayConfig = await agentInstallFlow.AskGatewayQuestions(installConfig, apiServerClient, defsManager); // create the Identity Provider configuration if (agentInstallFlow.AddIDP) { installConfig.idpConfig = await helpers.idpTestables.addIdentityProvider(); } // traceability options if (installConfig.switches.isTaEnabled && !installConfig.switches.isHostedInstall) { installConfig.traceabilityConfig = await platform.getTraceabilityConfig(installConfig); } // create backup await createConfigBackup(agentInstallFlow.ConfigFiles, agentInstallFlow.GatewayDisplay); // run any install preprocess steps installConfig = await finishInstall(agentInstallFlow, installConfig, apiServerClient, platformClient, defsManager); // finalize gateway setup and output await agentInstallFlow.FinalizeGatewayInstall(installConfig, apiServerClient, defsManager); } catch (e) { log('command error', e); isCmdError = true; render.anyError(e); } finally { log('command complete'); if (isCmdError) process.exit(1); // not sure why explicit exit is needed, seems like download is causing it to hang for 10-20 sec process.exit(0); } }, desc: 'Amplify API Gateway / Apigee X Gateway / Amazon API Gateway / Azure API Gateway / Azure EventHub / Backstage / GitLab / Istio / Kafka /' + ' Graylog / IBM API Connect / SwaggerHub / Software AG WebMethods / Traceable / SAP API Portal / Sensedia / WSO2', options: { ..._types.commonCmdArgsDescription } }; async function getAgentVersions(agentInstallFlow, installConfig) { if (agentInstallFlow.AgentNameMap && !installConfig.switches.isHostedInstall && installConfig.switches.isDaEnabled) { installConfig.daVersion = await helpers.getLatestAgentVersion(agentInstallFlow.AgentNameMap[_types.AgentTypes.da]); } if (agentInstallFlow.AgentNameMap && !installConfig.switches.isHostedInstall && installConfig.switches.isTaEnabled) { installConfig.taVersion = await helpers.getLatestAgentVersion(agentInstallFlow.AgentNameMap[_types.AgentTypes.ta]); } } async function finishInstall(agentInstallFlow, installConfig, apiServerClient, platformClient, defsManager) { if (agentInstallFlow.InstallPreprocess) installConfig = await agentInstallFlow.InstallPreprocess(installConfig); // finalize Platform setup, only for non-hosted agents if (!installConfig.switches.isHostedInstall) { installConfig = await platform.finalizeCentralInstall(apiServerClient, platformClient, defsManager, installConfig); } return installConfig; } function checkUserRole(isCentralAdmin, isPlatformAdmin, accountInfo, render) { if (!isCentralAdmin || !isPlatformAdmin) { if (!accountInfo || accountInfo.isPlatform) { render.error('Error: Not authorized. Account must be assigned the roles: Platform Admin, Engage Admin'); } else { render.error('Error: Not authorized. "Service Account" must be authorized with a user account with "Tooling Credentials" assigned the roles: Platform Admin, Engage Admin'); render.error('See: https://docs.axway.com/bundle/axwaycli-open-docs/page/docs/authentication/index.html#service-account-with-username-password'); } process.exit(1); } } const validateFrequency = lowerLimit => input => { let val = (0, _basicPrompts.validateRegex)(helpers.frequencyRegex, helpers.invalidValueExampleErrMsg('frequency', '3d5h12m'))(input); if (typeof val === 'string') { return val; } let r = input.toString().match(/^(\d*)m/); if (r) { // only minutes let mins = r[1]; const minValue = parseInt(mins, 10); const minimumRequired = lowerLimit !== null && lowerLimit !== void 0 ? lowerLimit : 30; // Use provided lowerLimit or default to 30 if (minValue < minimumRequired) { return `Minimum frequency is ${minimumRequired}m`; } } return true; }; exports.validateFrequency = validateFrequency;