@axway/axway-central-cli
Version:
Manage APIs, services and publish to the Amplify Marketplace
186 lines (175 loc) • 11 kB
JavaScript
;
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 _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
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;
// Do not ask Traceability questions in offline mode
if (!traceabilityConfig.usageReportingOffline) {
console.log('\nCONNECTION TO TRACEABILITY MODULE:');
const traceabilityProtocol = await helpers.askIngestionProtocol();
traceabilityConfig.protocol = traceabilityProtocol;
traceabilityConfig.host = helpers.getIngestionHost(installConfig.centralConfig.region, _CoreConfigController.CoreConfigController.getEnv(), installConfig.centralConfig.deployment, traceabilityProtocol);
}
return traceabilityConfig;
};
exports.getTraceabilityConfig = getTraceabilityConfig;
const getCentralConfig = async (apiServerClient, platformClient, defsManager, apicDeployment, installConfig) => {
// initiate CentralAgentConfig
let centralConfig = installConfig.centralConfig;
await centralConfig.setBaseHost();
centralConfig.authUrl = `${_CoreConfigController.CoreConfigController.getAuthUrl()}/auth`;
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);
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 and GRAYLOG (atm)
const isCaType = installConfig.gatewayType === _types.GatewayTypes.TRACEABLE || 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.Regions.EU]: {
[_types.Platforms.prod]: _types.APICDeployments.EU,
[_types.Platforms.staging]: _types.APICDeployments.EUStaging
},
[_types.Regions.AP]: {
[_types.Platforms.prod]: _types.APICDeployments.AP,
[_types.Platforms.staging]: _types.APICDeployments.APStaging
}
};
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;