@axway/axway-central-cli
Version:
Manage APIs, services and publish to the Amplify Marketplace
279 lines (261 loc) • 15.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.validateFrequency = 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 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 platform = _interopRequireWildcard(require("./platform"));
var backstageAgent = _interopRequireWildcard(require("./backstageAgents"));
var sapApiPortalAgent = _interopRequireWildcard(require("./sapApiPortalAgents"));
var wso2Agents = _interopRequireWildcard(require("./wso2Agents"));
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 }; }
const {
log
} = (0, _snooplogg.default)('engage: install: agents');
const localhost = exports.localhost = 'localhost';
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.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.WSO2]: wso2Agents.WSO2InstallMethods
};
const saasAgentInstallFlows = {
[_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
};
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);
installConfig.centralConfig.singleEntryPointUrl = _types.SingleEntryPointUrls[installConfig.centralConfig.region];
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).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
});
// 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) {
// 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 / Amazon API Gateway / Azure API Gateway / Istio / Apigee X Gateway / GitHub / GitLab / Kafka / SwaggerHub/ Software AG WebMethods',
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 = () => 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];
if (parseInt(mins, 10) < 30) {
return 'Minimum frequency is 30m';
}
}
return true;
};
exports.validateFrequency = validateFrequency;