@axway/axway-central-cli
Version:
Manage APIs, services and publish to the Amplify Marketplace
224 lines (216 loc) • 11.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.testables = exports.gatewayConnectivity = exports.defaultLogFiles = exports.completeInstall = exports.askConfigType = exports.askBundleType = exports.ConfigFiles = exports.ApigeeXInstallMethods = 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 helpers = _interopRequireWildcard(require("./helpers"));
var _apigeexTemplates = require("./helpers/templates/apigeexTemplates");
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 }; }
// @ts-ignore
const {
log
} = (0, _snooplogg.default)('engage: install: agents: apigeeX');
const daImage = `${_types.PublicDockerRepoBaseUrl}${_types.BasePaths.DockerAgentPublicRepo}/${_types.AgentNames.APIGEEX_DA}`;
const taImage = `${_types.PublicDockerRepoBaseUrl}${_types.BasePaths.DockerAgentPublicRepo}/${_types.AgentNames.APIGEEX_TA}`;
const defaultLogFiles = exports.defaultLogFiles = '/group-*_instance-*.log';
// 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}`,
ApigeeXDABinaryFile: 'discovery_agent',
ApigeeXDAYaml: 'discovery_agent.yml',
ApigeeXTABinaryFile: 'traceability_agent',
ApigeeXTAYaml: 'traceability_agent.yml'
};
// ApigeeXPrompts - prompts for user inputs
const ApigeeXPrompts = {
AUTHENTICATION_TYPE: 'Authenticate with an Impersonation of a Service Account or by providing a Credential File',
PROJECT_ID: 'Enter the APIGEE X Project ID the agent will use',
DEVELOPER_EMAIL_ADDRESS: 'Enter the APIGEE X Developer Email Address the agent will use',
AUTH_FILE_NAME: 'Enter the GCP key file name (place in the same directory as your Axway public and private keys)',
UPLOAD_CREDENTIAL_FILE: 'Upload a JSON Credential file to be used for APIGEE X Authentication',
DA_FREQUENCY: 'How often should the discovery run, leave blank for integrating in CI/CD process',
TA_FREQUENCY: 'How often should the traffic collection run, leave blank for manual trigger only',
QUEUE: 'Do you want to discover immediately after installation',
ENTER_MORE: 'Do you want to enter another {0} for {1}',
FILTER_METRICS: 'Do you want metrics filtering?',
FILTERED_APIS: 'Enter APIs to filter metrics for',
ENTER_MORE_APIS: 'Do you want to add another API?',
ENVIRONMENT: 'Enter the Apigee Envirnoment to filter discovered APIs/metrics'
};
const askBundleType = async gateway => {
console.log(gateway);
if (gateway === _types.GatewayTypes.APIGEEX_GATEWAY) {
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 Apigee X agents
//
exports.askConfigType = askConfigType;
const askApigeeXProjectId = async () => await (0, _basicPrompts.askInput)({
msg: ApigeeXPrompts.PROJECT_ID,
validate: (0, _basicPrompts.validateRegex)(helpers.APIGEEXRegexPatterns.APIGEEX_REGEXP_PROJECT_ID, helpers.invalidValueExampleErrMsg('Project ID', 'rd-amplify-apigee-x'))
});
const askApigeeXDeveloperEmailAddress = async () => await (0, _basicPrompts.askInput)({
msg: ApigeeXPrompts.DEVELOPER_EMAIL_ADDRESS
});
const askApigeeXAuthFileName = async () => await (0, _basicPrompts.askInput)({
msg: ApigeeXPrompts.AUTH_FILE_NAME
});
const askApigeeXEnvironment = async () => await (0, _basicPrompts.askInput)({
msg: ApigeeXPrompts.ENVIRONMENT,
defaultValue: '',
allowEmptyInput: true
});
const askApigeeXMetricFilterConfig = async () => {
let filteredAPIs = [];
let filterMetricsEnabled = (await (0, _basicPrompts.askList)({
msg: ApigeeXPrompts.FILTER_METRICS,
default: _types.YesNo.No,
choices: _types.YesNoChoices
})) === _types.YesNo.Yes;
if (filterMetricsEnabled) {
let askFilteredAPIs = true;
console.log(_chalk.default.gray("An array of APIs to filter metrics for"));
while (askFilteredAPIs) {
const api = await (0, _basicPrompts.askInput)({
msg: ApigeeXPrompts.FILTERED_APIS,
allowEmptyInput: true
});
filteredAPIs.push(api);
askFilteredAPIs = (await (0, _basicPrompts.askList)({
msg: ApigeeXPrompts.ENTER_MORE_APIS,
default: _types.YesNo.No,
choices: _types.YesNoChoices
})) === _types.YesNo.Yes;
}
}
return new _types.ApigeeMetricsFilterConfig(filterMetricsEnabled, filteredAPIs);
};
const gatewayConnectivity = async installConfig => {
const apigeeXAgentValues = new _apigeexTemplates.ApigeeXAgentValues();
console.log('\nCONNECTION TO APIGEE X API GATEWAY:');
console.log(_chalk.default.gray(`The discovery agent needs to connect to the APIGEE X API Gateway to discover API's for publishing to Amplify.\n`));
// Apigee X Discovery Agent Prompts
if (installConfig.switches.isDaEnabled) {
console.log(_chalk.default.gray(`\nDiscovery Agent Configuration\n`));
await askDiscoveryPrompts(apigeeXAgentValues);
}
// Apigee X Traceability Agent Prompts
if (installConfig.switches.isTaEnabled) {
console.log(_chalk.default.gray(`\nTraceability Agent Configuration\n`));
await askTraceabilityPrompts(apigeeXAgentValues);
}
return apigeeXAgentValues;
};
exports.gatewayConnectivity = gatewayConnectivity;
const generateSuccessHelpMsg = installConfig => {
if (installConfig.centralConfig.ampcDosaInfo.isNew && !installConfig.switches.isHelmInstall) {
console.log(_chalk.default.yellow('\nPlease make sure to copy the "private_key.pem" and "public_key.pem" files for the existing service account you selected.'));
}
dockerSuccessMsg(installConfig);
console.log(_chalk.default.gray(`\nAdditional information about agent features can be found here:\n${helpers.agentsDocsUrl.APIGEEX}`));
};
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');
}
};
// ApigeeX DA prompts
async function askDiscoveryPrompts(apigeeXAgentValues) {
// Apigee X ProjectId
apigeeXAgentValues.projectId = await askApigeeXProjectId();
// Apigee X Developer Email Address
apigeeXAgentValues.developerEmailAddress = await askApigeeXDeveloperEmailAddress();
// Apigee X Auth File Path
apigeeXAgentValues.fileName = await askApigeeXAuthFileName();
// Apigee X Environment
apigeeXAgentValues.environment = await askApigeeXEnvironment();
}
async function askTraceabilityPrompts(apigeeXAgentValues) {
// Apigee X Filter metrics
apigeeXAgentValues.metricsFilter = await askApigeeXMetricFilterConfig();
}
const completeInstall = async installConfig => {
/**
* Create agent resources
*/
const apigeeXAgentValues = installConfig.gatewayConfig;
// Add final settings to apigeeXAgentValues
apigeeXAgentValues.centralConfig = installConfig.centralConfig;
apigeeXAgentValues.traceabilityConfig = installConfig.traceabilityConfig;
console.log('Generating the configuration file(s)...');
if (installConfig.switches.isDaEnabled) {
(0, _utils.writeTemplates)(ConfigFiles.DAEnvVars, apigeeXAgentValues, helpers.apigeeXDAEnvVarTemplate);
}
if (installConfig.switches.isTaEnabled) {
(0, _utils.writeTemplates)(ConfigFiles.TAEnvVars, apigeeXAgentValues, helpers.apigeeXTAEnvVarTemplate);
}
console.log('Configuration file(s) have been successfully created.\n');
generateSuccessHelpMsg(installConfig);
};
exports.completeInstall = completeInstall;
const ApigeeXInstallMethods = exports.ApigeeXInstallMethods = {
GetBundleType: askBundleType,
GetDeploymentType: askConfigType,
AskGatewayQuestions: gatewayConnectivity,
FinalizeGatewayInstall: completeInstall,
ConfigFiles: Object.values(ConfigFiles),
AgentNameMap: {
[_types.AgentTypes.da]: _types.AgentNames.APIGEEX_DA,
[_types.AgentTypes.ta]: _types.AgentNames.APIGEEX_TA
},
GatewayDisplay: _types.GatewayTypes.APIGEEX_GATEWAY
};
const testables = exports.testables = {
ApigeeXPrompts,
ConfigFiles,
defaultLogFiles
};