@axway/axway-central-cli
Version:
Manage APIs, services and publish to the Amplify Marketplace
199 lines (192 loc) • 11.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.testables = exports.gatewayConnectivity = exports.defaultLogFiles = exports.completeInstall = exports.askConfigType = exports.askBundleType = exports.SAPAPIPortalInstallMethods = exports.ConfigFiles = 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 _sapApiPortalTemplates = require("./helpers/templates/sapApiPortalTemplates");
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)('central: install: agents: SAP API Portal');
const daImage = `${_types.PublicDockerRepoBaseUrl}${_types.BasePaths.DockerAgentPublicRepo}/${_types.AgentNames.SAPAPIPORTAL_DA}`;
const taImage = `${_types.PublicDockerRepoBaseUrl}${_types.BasePaths.DockerAgentPublicRepo}/${_types.AgentNames.SAPAPIPORTAL_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}`,
SAPAPIPortalDABinaryFile: 'discovery_agent',
SAPAPIPortalDAYaml: 'discovery_agent.yml',
SAPAPIPortalTABinaryFile: 'traceability_agent',
SAPAPIPortalTAYaml: 'traceability_agent.yml'
};
// SAPAPIPortalPrompts - prompts for user inputs
const SAPAPIPortalPrompts = {
configTypeMsg: 'Select the mode of installation',
enterAuthTokenURL: 'Enter the token URL used for agent authentication to SAP',
enterAuthAPIPortalBaseURL: 'Enter the SAP API Portal baseURL',
enterAuthAPIPortalClientID: 'Enter the SAP API Portal ClientID',
enterAuthAPIPortalClientSecret: 'Enter the SAP API Portal ClientSecret',
enterAuthDevPortalBaseURL: 'Enter the SAP Dev Portal baseURL',
enterAuthDevPortalClientID: 'Enter the SAP Dev Portal ClientID',
enterAuthDevPortalClientSecret: 'Enter the SAP Dev Portal ClientSecret',
enterDeveloperEmail: 'Enter the SAP developer email',
selectSpecCreateUnstructuredAPI: 'Select whether to create unstructured APIs for invalid/unknown API specs'
};
const askBundleType = async () => {
return await (0, _basicPrompts.askList)({
msg: helpers.agentMessages.selectAgentType,
choices: [_types.BundleType.ALL_AGENTS, _types.BundleType.DISCOVERY, _types.BundleType.TRACEABILITY]
});
};
exports.askBundleType = askBundleType;
const askConfigType = async () => {
return _types.AgentConfigTypes.DOCKERIZED;
};
//
// Questions for the configuration of SAP API Portal agents
//
exports.askConfigType = askConfigType;
const askAuthTokenURL = async () => await (0, _basicPrompts.askInput)({
msg: SAPAPIPortalPrompts.enterAuthTokenURL
});
const askAuthAPIPortalBaseURL = async () => await (0, _basicPrompts.askInput)({
msg: SAPAPIPortalPrompts.enterAuthAPIPortalBaseURL
});
const askAuthAPIPortalClientID = async () => await (0, _basicPrompts.askInput)({
msg: SAPAPIPortalPrompts.enterAuthAPIPortalClientID
});
const askAuthAPIPortalClientSecret = async () => await (0, _basicPrompts.askInput)({
msg: SAPAPIPortalPrompts.enterAuthAPIPortalClientSecret
});
const askAuthDevPortalBaseURL = async () => await (0, _basicPrompts.askInput)({
msg: SAPAPIPortalPrompts.enterAuthDevPortalBaseURL
});
const askAuthDevPortalClientID = async () => await (0, _basicPrompts.askInput)({
msg: SAPAPIPortalPrompts.enterAuthDevPortalClientID
});
const askAuthDevPortalClientSecret = async () => await (0, _basicPrompts.askInput)({
msg: SAPAPIPortalPrompts.enterAuthDevPortalClientSecret
});
const askDeveloperEmail = async () => await (0, _basicPrompts.askInput)({
msg: SAPAPIPortalPrompts.enterDeveloperEmail
});
const askSpecCreateUnstructuredAPI = async () => (await (0, _basicPrompts.askList)({
msg: SAPAPIPortalPrompts.selectSpecCreateUnstructuredAPI,
default: _types.YesNo.No,
choices: _types.YesNoChoices
})) === _types.YesNo.Yes;
const gatewayConnectivity = async installConfig => {
const agentValues = new _sapApiPortalTemplates.SAPApiPortalAgentValues();
console.log('\nCONNECTION TO SAP API Portal:');
console.log(_chalk.default.gray(`The discovery agent needs to connect to the SAP API Portal Gateway to discover API's for publishing to Amplify.\nThe traceability agent needs to connect to SAP API Portal for collecting APIs transactions. These will be forwarded to the Business Insights.\n`));
await askCommonPrompts(agentValues);
// SAP API Portal Discovery Agent Prompts
if (installConfig.switches.isDaEnabled) {
console.log(_chalk.default.gray(`\nDiscovery Agent Configuration\n`));
await askDiscoveryPrompts(agentValues);
}
return agentValues;
};
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.SAPAPIPORTAL}`));
};
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');
}
};
async function askCommonPrompts(agentValues) {
agentValues.authTokenURL = await askAuthTokenURL();
agentValues.authAPIPortalBaseURL = await askAuthAPIPortalBaseURL();
agentValues.authAPIPortalClientID = await askAuthAPIPortalClientID();
agentValues.authAPIPortalClientSecret = await askAuthAPIPortalClientSecret();
}
// SAP API Portal DA prompts
async function askDiscoveryPrompts(agentValues) {
agentValues.authDevPortalBaseURL = await askAuthDevPortalBaseURL();
agentValues.authDevPortalClientID = await askAuthDevPortalClientID();
agentValues.authDevPortalClientSecret = await askAuthDevPortalClientSecret();
agentValues.developerEmail = await askDeveloperEmail();
agentValues.specCreateUnstructuredAPI = await askSpecCreateUnstructuredAPI();
}
const completeInstall = async installConfig => {
/**
* Create agent resources
*/
const agentValues = installConfig.gatewayConfig;
// Add final settings to SAP API Portal agentValues
agentValues.centralConfig = installConfig.centralConfig;
agentValues.traceabilityConfig = installConfig.traceabilityConfig;
console.log('Generating the configuration file(s)...');
if (installConfig.switches.isDaEnabled) {
(0, _utils.writeTemplates)(ConfigFiles.DAEnvVars, agentValues, _sapApiPortalTemplates.sapAPIPortalDAEnvVarTemplate);
}
if (installConfig.switches.isTaEnabled) {
(0, _utils.writeTemplates)(ConfigFiles.TAEnvVars, agentValues, _sapApiPortalTemplates.sapAPIPortalTAEnvVarTemplate);
}
console.log('Configuration file(s) have been successfully created.\n');
generateSuccessHelpMsg(installConfig);
};
exports.completeInstall = completeInstall;
const SAPAPIPortalInstallMethods = exports.SAPAPIPortalInstallMethods = {
GetBundleType: askBundleType,
GetDeploymentType: askConfigType,
AskGatewayQuestions: gatewayConnectivity,
FinalizeGatewayInstall: completeInstall,
ConfigFiles: Object.values(ConfigFiles),
AgentNameMap: {
[_types.AgentTypes.da]: _types.AgentNames.SAPAPIPORTAL_DA,
[_types.AgentTypes.ta]: _types.AgentNames.SAPAPIPORTAL_TA
},
GatewayDisplay: _types.GatewayTypes.SAPAPIPORTAL
};
const testables = exports.testables = {
SAPAPIPortalPrompts,
ConfigFiles,
defaultLogFiles
};