UNPKG

@axway/axway-central-cli

Version:

Manage APIs, services and publish to the Amplify Marketplace

178 lines (168 loc) 10.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getTraceabilityConfig = exports.getCentralConfig = exports.getApicDeployment = exports.finalizeCentralInstall = void 0; var _chalk = _interopRequireDefault(require("chalk")); var _basicPrompts = require("../../common/basicPrompts"); var _CliConfigManager = require("../../common/CliConfigManager"); var _CoreConfigController = require("../../common/CoreConfigController"); var _types = require("../../common/types"); var _awsAgents = require("./awsAgents"); 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 }; } // // Complex prompts // const askTeamName = async client => { var _teams$find; const teams = await client.getTeams(); if (!(teams !== null && teams !== void 0 && teams.length)) { throw new Error('Account has no teams!'); } return (0, _basicPrompts.askList)({ msg: helpers.envMessages.selectTeam, choices: teams.map(t => t.name).sort((name1, name2) => name1.localeCompare(name2)), default: (_teams$find = teams.find(t => t.default)) === null || _teams$find === void 0 ? void 0 : _teams$find.name }); }; const askIsProductionEnvironment = async () => { return (await (0, _basicPrompts.askList)({ msg: helpers.envMessages.isProduction, choices: _types.YesNoChoices, default: _types.YesNo.Yes })) === _types.YesNo.Yes; }; const getTraceabilityConfig = async installConfig => { let traceabilityConfig = new _types.TraceabilityConfig(); if (installConfig.gatewayType === _types.GatewayTypes.AWS_GATEWAY && installConfig.gatewayConfig.cloudFormationConfig.DeploymentType === _awsAgents.DeploymentTypes.ECS_FARGATE) { return traceabilityConfig; } traceabilityConfig.usageReportingOffline = installConfig.bundleType === _types.BundleType.TRACEABILITY_OFFLINE; return traceabilityConfig; }; exports.getTraceabilityConfig = getTraceabilityConfig; const getCentralConfig = async (apiServerClient, platformClient, defsManager, apicDeployment, installConfig) => { // initiate CentralAgentConfig let centralConfig = installConfig.centralConfig; centralConfig.deployment = apicDeployment || getApicDeployment(centralConfig.region, _CoreConfigController.CoreConfigController.getEnv()); // apic config console.log('\nCONNECTION TO AMPLIFY PLATFORM:'); console.log(_chalk.default.gray(`The agents need access to the Amplify Platform to register services.`)); // create/find environment centralConfig.orgId = await helpers.getCurrentUserOrgId(); centralConfig.ampcEnvInfo = await helpers.askEnvironmentName(apiServerClient, defsManager, centralConfig.axwayManaged, installConfig.gatewayType); centralConfig.production = centralConfig.ampcEnvInfo.isNew ? await askIsProductionEnvironment() : false; if (installConfig.gatewayType === _types.GatewayTypes.GRAYLOG) { const updatedRefEnvs = await helpers.askReferencedEnvironments(apiServerClient, defsManager, centralConfig.ampcEnvInfo); const compareRefs = (a, b) => { return (a === null || a === void 0 ? void 0 : a.length) === (b === null || b === void 0 ? void 0 : b.length) && (a === null || a === void 0 ? void 0 : a.every(element => b === null || b === void 0 ? void 0 : b.includes(element))); }; if (!compareRefs(updatedRefEnvs, centralConfig.ampcEnvInfo.referencedEnvironments)) { centralConfig.ampcEnvInfo.referencedEnvironments = updatedRefEnvs; centralConfig.ampcEnvInfo.isUpdated = true; } } if (!installConfig.switches.isOrgRep) { centralConfig.ampcTeamName = await askTeamName(platformClient); } centralConfig.ampcDosaInfo = { clientId: '', name: '', isNew: false }; if (installConfig.bundleType !== _types.BundleType.TRACEABILITY_OFFLINE && !installConfig.switches.isHostedInstall) { centralConfig.ampcDosaInfo = await helpers.askDosaClientId(platformClient); } // Get the DA Agent name centralConfig.daAgentName = ''; // Istio will not prompt for agent name. Remove when that ability exists if (installConfig.switches.isDaEnabled && !installConfig.switches.isHostedInstall) { centralConfig.daAgentName = await helpers.askAgentName(apiServerClient, defsManager, _types.AgentTypes.da, centralConfig.ampcEnvInfo.name); } // Initialize agent names centralConfig.taAgentName = ''; centralConfig.caAgentName = ''; // Determine if we should use CA (compliance) or TA agent. Compliance is good for TRACEABLE, AKAMAI and GRAYLOG (atm) const isCaType = installConfig.gatewayType === _types.GatewayTypes.TRACEABLE || installConfig.gatewayType === _types.GatewayTypes.AKAMAI || installConfig.gatewayType === _types.GatewayTypes.GRAYLOG; const agentType = isCaType ? _types.AgentTypes.ca : _types.AgentTypes.ta; const agentNameProperty = isCaType ? 'caAgentName' : 'taAgentName'; if (installConfig.switches.isTaEnabled && !installConfig.switches.isHostedInstall) { const agentName = await helpers.askAgentName(apiServerClient, defsManager, agentType, centralConfig.ampcEnvInfo.name); centralConfig[agentNameProperty] = agentName; } return centralConfig; }; exports.getCentralConfig = getCentralConfig; const finalizeCentralInstall = async (apiServerClient, platformClient, defsManager, installConfig) => { /** * Create agent resources */ console.log('Creating agent resources'); if (installConfig.centralConfig.ampcDosaInfo.isNew) { installConfig.centralConfig.dosaAccount = await helpers.createDosaAndCerts(platformClient, installConfig.centralConfig.ampcDosaInfo.name); } else { installConfig.centralConfig.dosaAccount.clientId = installConfig.centralConfig.ampcDosaInfo.clientId; } installConfig.centralConfig.dosaAccount.updateKeyTemplateValues(installConfig.deploymentType); let refEnvSubResource; if (installConfig.centralConfig.ampcEnvInfo.referencedEnvironments) { refEnvSubResource = { references: { managedEnvironments: installConfig.centralConfig.ampcEnvInfo.referencedEnvironments } }; } // environment name installConfig.centralConfig.environment = installConfig.centralConfig.ampcEnvInfo.isNew ? await helpers.createByResourceType(apiServerClient, defsManager, installConfig.centralConfig.ampcEnvInfo.name, 'Environment', 'env', { axwayManaged: installConfig.centralConfig.axwayManaged, production: installConfig.centralConfig.production }, '', refEnvSubResource) : installConfig.centralConfig.ampcEnvInfo.name; if (installConfig.centralConfig.ampcEnvInfo.isUpdated) { await helpers.updateSubResourceType(apiServerClient, defsManager, installConfig.centralConfig.ampcEnvInfo.name, 'Environment', 'env', '', refEnvSubResource); } // Create DiscoveryAgent Resource unless gateway type is Istio. This can be removed when this is available for Istio if (installConfig.centralConfig.daAgentName != '') { installConfig.centralConfig.daAgentName = await helpers.createNewAgentResource(apiServerClient, defsManager, installConfig.centralConfig.environment, _types.GatewayTypeToDataPlane[installConfig.gatewayType], _types.AgentResourceKind.da, _types.AgentTypes.da, installConfig.centralConfig.ampcTeamName, installConfig.centralConfig.daAgentName); } // Create TraceabilityAgent Resource if (installConfig.centralConfig.taAgentName != '') { installConfig.centralConfig.taAgentName = await helpers.createNewAgentResource(apiServerClient, defsManager, installConfig.centralConfig.environment, _types.GatewayTypeToDataPlane[installConfig.gatewayType], _types.AgentResourceKind.ta, _types.AgentTypes.ta, installConfig.centralConfig.ampcTeamName, installConfig.centralConfig.taAgentName); } // Create ComplianceAgent Resource if (installConfig.centralConfig.caAgentName != '') { installConfig.centralConfig.caAgentName = await helpers.createNewAgentResource(apiServerClient, defsManager, installConfig.centralConfig.environment, _types.GatewayTypeToDataPlane[installConfig.gatewayType], _types.AgentResourceKind.ca, _types.AgentTypes.ca, installConfig.centralConfig.ampcTeamName, installConfig.centralConfig.caAgentName, undefined, undefined, undefined, { managedEnvironment: installConfig.gatewayConfig.centralEnvironments } // cast applied here ); } if (installConfig.bundleType === _types.BundleType.TRACEABILITY_OFFLINE || installConfig.gatewayType === _types.GatewayTypes.ISTIO) { installConfig.centralConfig.environmentId = await helpers.getEnvironmentId(apiServerClient, defsManager, installConfig.centralConfig.environment); } return installConfig; }; exports.finalizeCentralInstall = finalizeCentralInstall; const getApicDeployment = (region, env) => { var _deployments$region; const deployments = { [_types.Regions.US]: { [_types.Platforms.prod]: _types.APICDeployments.US, [_types.Platforms.staging]: _types.APICDeployments.TEAMS, [_types.Platforms.preprod]: _types.APICDeployments.USPreprod }, [_types.Regions.EU]: { [_types.Platforms.prod]: _types.APICDeployments.EU, [_types.Platforms.staging]: _types.APICDeployments.EUStaging, [_types.Platforms.preprod]: _types.APICDeployments.EUPreprod }, [_types.Regions.AP]: { [_types.Platforms.prod]: _types.APICDeployments.AP, [_types.Platforms.staging]: _types.APICDeployments.APStaging, [_types.Platforms.preprod]: _types.APICDeployments.APPreprod } }; const savedDeployment = new _CliConfigManager.CliConfigManager().getAll()['apic-deployment']; return savedDeployment || (deployments === null || deployments === void 0 ? void 0 : (_deployments$region = deployments[region]) === null || _deployments$region === void 0 ? void 0 : _deployments$region[env]) || _types.APICDeployments.US; }; exports.getApicDeployment = getApicDeployment;