UNPKG

@axway/axway-central-cli

Version:

Manage APIs, services and publish to the Amplify Marketplace

304 lines (300 loc) 15.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.testables = exports.gatewayConnectivity = exports.completeInstall = exports.askSaslMechanism = exports.askIsSchemaRegistryAuthEnabled = exports.askIsCloudEnabled = exports.askConfigType = exports.askBundleType = exports.SaslMechanismTypes = exports.KafkaInstallMethods = exports.DeploymentTypes = 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 _agents = require("./agents"); var helpers = _interopRequireWildcard(require("./helpers")); var _kafkaTemplates = require("./helpers/templates/kafkaTemplates"); 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 }; } // @ts-ignore const { log } = (0, _snooplogg.default)('central: install: agents: kafka'); const daImage = `${_types.PublicDockerRepoBaseUrl}${_types.BasePaths.DockerAgentPublicRepo}/${_types.AgentNames.KAFKA_DA}`; const taImage = `${_types.PublicDockerRepoBaseUrl}${_types.BasePaths.DockerAgentPublicRepo}/${_types.AgentNames.KAFKA_TA}`; // 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}` }; // DeploymentTypes - types of Kafka cluster deployments let DeploymentTypes = exports.DeploymentTypes = /*#__PURE__*/function (DeploymentTypes) { DeploymentTypes["CONFLUENT_CLOUD"] = "Confluent Cloud"; DeploymentTypes["CONFLUENT_PLATFORM"] = "Confluent Platform"; return DeploymentTypes; }({}); // SaslMechanismTypes - SASL authentication mechanism types let SaslMechanismTypes = exports.SaslMechanismTypes = /*#__PURE__*/function (SaslMechanismTypes) { SaslMechanismTypes["SCRAM_SHA_256"] = "SCRAM-SHA-256"; SaslMechanismTypes["SCRAM_SHA_512"] = "SCRAM-SHA-512"; SaslMechanismTypes["PLAIN"] = "PLAIN"; SaslMechanismTypes["OAUTHBEARER"] = "OAUTHBEARER"; SaslMechanismTypes["NONE"] = "NONE"; return SaslMechanismTypes; }({}); // KafkaPrompts - prompts for user inputs const prompts = { deploymentTypeMsg: 'Select the type of deployment you wish to configure', enterEnvironmentId: 'Enter the Environment Id', enterClusterId: 'Enter the Cluster Id', enterCloudAPIKey: 'Enter the Cloud API Key Id', enterCloudAPISecret: 'Enter the Cloud API Key Secret', enterClusterServer: 'Enter the Bootstrap Server Name', enterClusterAPIKey: 'Enter the Cluster API Key Id', enterClusterAPISecret: 'Enter the Cluster API Key Secret', saslMechanismMsg: "Select the SASL Mechanism you wish to use for authentication", enterSaslUsername: "Enter the SASL Username", enterSaslPassword: "Enter the SASL Password", enterSaslOAuthTokenUrl: "Enter the SASL/OAUTHBEARER Token Url", enterSaslOAuthClientId: "Enter the SASL/OAUTHBEARER Client Id", enterSaslOAuthClientSecret: "Enter the SASL/OAUTHBEARER Client Secret", enterSaslOAuthClientScopes: "Enter the SASL/OAUTHBEARER Client Scopes(comma separated list)", schemaRegistryEnabledMsg: 'Do you want to use Schema Registry with Kafka cluster?', enterSchemaRegistryUrl: 'Enter the Schema Registry Url', schemaRegistryAuthEnabled: 'Do you want to authenticate Schema Registry with SASL mechanism?', enterSchemaRegistryAPIKey: 'Enter the Schema Registry API Key Id', enterSchemaRegistryAPISecret: 'Enter the Schema Registry API Key Secret' }; 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 Kafka agents // exports.askConfigType = askConfigType; const askIsCloudEnabled = async () => { const deploymentType = await (0, _basicPrompts.askList)({ msg: prompts.deploymentTypeMsg, default: DeploymentTypes.CONFLUENT_CLOUD, choices: [{ name: DeploymentTypes.CONFLUENT_CLOUD, value: DeploymentTypes.CONFLUENT_CLOUD }, { name: DeploymentTypes.CONFLUENT_PLATFORM, value: DeploymentTypes.CONFLUENT_PLATFORM }] }); return deploymentType == DeploymentTypes.CONFLUENT_CLOUD; }; exports.askIsCloudEnabled = askIsCloudEnabled; const askEnvironmentId = async () => await (0, _basicPrompts.askInput)({ msg: prompts.enterEnvironmentId }); const askClusterId = async () => await (0, _basicPrompts.askInput)({ msg: prompts.enterClusterId }); const askCloudAPIKey = async () => await (0, _basicPrompts.askInput)({ msg: prompts.enterCloudAPIKey }); const askCloudAPISecret = async () => await (0, _basicPrompts.askInput)({ msg: prompts.enterCloudAPISecret }); const askClusterServer = async () => await (0, _basicPrompts.askInput)({ msg: prompts.enterClusterServer, validate: (0, _basicPrompts.validateRegex)(helpers.KafkaRegexPatterns.bootstrapServerRegex, helpers.invalidValueExampleErrMsg('Bootstrap Server Name', 'SASL_SSL://somehost.testdomain.com:9092')) }); const askClusterAPIKey = async () => await (0, _basicPrompts.askInput)({ msg: prompts.enterClusterAPIKey }); const askClusterAPISecret = async () => await (0, _basicPrompts.askInput)({ msg: prompts.enterClusterAPISecret }); const askSaslMechanism = async () => { return await (0, _basicPrompts.askList)({ msg: prompts.saslMechanismMsg, default: SaslMechanismTypes.PLAIN, choices: [{ name: SaslMechanismTypes.NONE, value: SaslMechanismTypes.NONE }, { name: SaslMechanismTypes.PLAIN, value: SaslMechanismTypes.PLAIN }, { name: SaslMechanismTypes.SCRAM_SHA_256, value: SaslMechanismTypes.SCRAM_SHA_256 }, { name: SaslMechanismTypes.SCRAM_SHA_512, value: SaslMechanismTypes.SCRAM_SHA_512 }, { name: SaslMechanismTypes.OAUTHBEARER, value: SaslMechanismTypes.OAUTHBEARER }] }); }; exports.askSaslMechanism = askSaslMechanism; const askSaslOAuthBearerTokenUrl = async () => await (0, _basicPrompts.askInput)({ msg: prompts.enterSaslOAuthTokenUrl, allowEmptyInput: false, validate: (0, _basicPrompts.validateRegex)(helpers.KafkaRegexPatterns.urlRegex, helpers.invalidValueExampleErrMsg('Token URL', 'https://www.testdomain.com/oauth/token')) }); const askSaslOAuthBearerClientId = async () => await (0, _basicPrompts.askInput)({ msg: prompts.enterSaslOAuthClientId, allowEmptyInput: false }); const askSaslOAuthBearerClientSecret = async () => await (0, _basicPrompts.askInput)({ msg: prompts.enterSaslOAuthClientSecret, allowEmptyInput: false }); const askSaslOAuthBearerScopes = async () => await (0, _basicPrompts.askInput)({ msg: prompts.enterSaslOAuthClientScopes, allowEmptyInput: true }); const askSaslUsername = async () => await (0, _basicPrompts.askInput)({ msg: prompts.enterSaslUsername }); const askSaslPassword = async () => await (0, _basicPrompts.askInput)({ msg: prompts.enterSaslPassword }); const askIsSchemaRegistryEnabled = async () => { const enabled = await (0, _basicPrompts.askList)({ msg: prompts.schemaRegistryEnabledMsg, default: _types.YesNo.Yes, choices: _types.YesNoChoices }); return enabled == _types.YesNo.Yes; }; const askIsSchemaRegistryAuthEnabled = async () => { const enabled = await (0, _basicPrompts.askList)({ msg: prompts.schemaRegistryAuthEnabled, default: _types.YesNo.Yes, choices: _types.YesNoChoices }); return enabled == _types.YesNo.Yes; }; exports.askIsSchemaRegistryAuthEnabled = askIsSchemaRegistryAuthEnabled; const askSchemaRegistryUrl = async () => await (0, _basicPrompts.askInput)({ msg: prompts.enterSchemaRegistryUrl, validate: (0, _basicPrompts.validateRegex)(helpers.KafkaRegexPatterns.urlRegex, helpers.invalidValueExampleErrMsg('Schema Registry Url', 'https://www.testdomain.com')) }); const askSchemaRegistryAPIKey = async () => await (0, _basicPrompts.askInput)({ msg: prompts.enterSchemaRegistryAPIKey }); const askSchemaRegistryAPISecret = async () => await (0, _basicPrompts.askInput)({ msg: prompts.enterSchemaRegistryAPISecret }); const gatewayConnectivity = async installConfig => { const kafkaAgentValues = new _kafkaTemplates.KafkaAgentValues(); kafkaAgentValues.cloudEnabled = await askIsCloudEnabled(); if (kafkaAgentValues.cloudEnabled) { kafkaAgentValues.cloudEnvironmentId = await askEnvironmentId(); kafkaAgentValues.cloudClusterId = await askClusterId(); kafkaAgentValues.cloudAPIKey = await askCloudAPIKey(); kafkaAgentValues.cloudAPISecret = await askCloudAPISecret(); kafkaAgentValues.clusterAPIKey = await askClusterAPIKey(); kafkaAgentValues.clusterAPISecret = await askClusterAPISecret(); } else { kafkaAgentValues.clusterServer = await askClusterServer(); kafkaAgentValues.clusterSaslMechanism = await askSaslMechanism(); if (kafkaAgentValues.clusterSaslMechanism !== SaslMechanismTypes.NONE) { if (kafkaAgentValues.clusterSaslMechanism == SaslMechanismTypes.OAUTHBEARER) { kafkaAgentValues.saslOauthTokenUrl = await askSaslOAuthBearerTokenUrl(); kafkaAgentValues.saslOauthClientId = await askSaslOAuthBearerClientId(); kafkaAgentValues.saslOauthClientSecret = await askSaslOAuthBearerClientSecret(); kafkaAgentValues.saslOauthClientScopes = await askSaslOAuthBearerScopes(); } else { kafkaAgentValues.clusterSaslUser = await askSaslUsername(); kafkaAgentValues.clusterSaslPassword = await askSaslPassword(); } } } if (installConfig.switches.isDaEnabled) { if (kafkaAgentValues.cloudEnabled) { kafkaAgentValues.schemaRegistryAPIKey = await askSchemaRegistryAPIKey(); kafkaAgentValues.schemaRegistryAPISecret = await askSchemaRegistryAPISecret(); } else { kafkaAgentValues.schemaRegistryEnabled = await askIsSchemaRegistryEnabled(); if (kafkaAgentValues.schemaRegistryEnabled) { kafkaAgentValues.schemaRegistryUrl = await askSchemaRegistryUrl(); kafkaAgentValues.schemaRegistryAuthEnabled = await askIsSchemaRegistryAuthEnabled(); } } } return kafkaAgentValues; }; exports.gatewayConnectivity = gatewayConnectivity; const generateSuccessHelpMsg = installConfig => { if (installConfig.centralConfig.ampcDosaInfo.isNew && !installConfig.switches.isHelmInstall) { console.log(_chalk.default.yellow(_agents.svcAccMsg)); } dockerSuccessMsg(installConfig); console.log(_chalk.default.gray(`\nAdditional information about agent features can be found here:\n${helpers.agentsDocsUrl.AZURE}`)); }; 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'); } }; const completeInstall = async installConfig => { // Add final settings to kafkaAgentsValues const kafkaAgentValues = installConfig.gatewayConfig; kafkaAgentValues.centralConfig = installConfig.centralConfig; kafkaAgentValues.traceabilityConfig = installConfig.traceabilityConfig; console.log('Generating the configuration file(s)...'); if (installConfig.switches.isDaEnabled) { (0, _utils.writeTemplates)(ConfigFiles.DAEnvVars, kafkaAgentValues, helpers.kafkaDAEnvVarTemplate); } if (installConfig.switches.isTaEnabled) { (0, _utils.writeTemplates)(ConfigFiles.TAEnvVars, kafkaAgentValues, helpers.kafkaTAEnvVarTemplate); } console.log('Configuration file(s) have been successfully created.\n'); generateSuccessHelpMsg(installConfig); }; exports.completeInstall = completeInstall; const KafkaInstallMethods = exports.KafkaInstallMethods = { GetBundleType: askBundleType, GetDeploymentType: askConfigType, AskGatewayQuestions: gatewayConnectivity, FinalizeGatewayInstall: completeInstall, ConfigFiles: Object.values(ConfigFiles), AgentNameMap: { [_types.AgentTypes.da]: _types.AgentNames.KAFKA_DA, [_types.AgentTypes.ta]: _types.AgentNames.KAFKA_TA }, GatewayDisplay: _types.GatewayTypes.KAFKA }; const testables = exports.testables = { prompts, ConfigFiles };