UNPKG

@axway/axway-central-cli

Version:

Manage APIs, services and publish to the Amplify Marketplace

179 lines (175 loc) 9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.testables = exports.installPreprocess = exports.gitLabPrompts = exports.gatewayConnectivity = exports.completeInstall = exports.askConfigType = exports.askBundleType = exports.GitLabInstallMethods = 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 _gitLabTemplates = require("./helpers/templates/gitLabTemplates"); 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: gitLab:'); const daImage = `${_types.PublicDockerRepoBaseUrl}${_types.BasePaths.DockerAgentPublicRepo}/${_types.AgentNames.GITLAB_DA}`; // ConfigFiles - all the config file that are used in the setup const ConfigFiles = exports.ConfigFiles = { DAEnvVars: `${helpers.configFiles.DA_ENV_VARS}` }; const gitLabPrompts = exports.gitLabPrompts = { ACCESS_TOKEN: 'Enter the GitLab Access Token the agent will use', BASE_URL: 'Enter the GitLab base URL that the agent will use', REPOSITORY_ID: 'Enter the GitLab Repository ID the agent will use', REPOSITORY_BRANCH: 'Enter the Repository Branch the agent will use', PATHS: 'Enter a Path within the repository that the agent will use', FILTERS: 'Enter a filter that the agent will use (Optional)', DA_FREQUENCY: 'How often should the discovery run, leave blank for integrating in CI/CD process', QUEUE: 'Do you want to discover immediately after installation', ENTER_MORE_PATHS: 'Do you want to enter another path ?', ENTER_MORE_FILTERS: 'Do you want to enter another filter ?' }; const askBundleType = async () => { return _types.BundleType.DISCOVERY; }; exports.askBundleType = askBundleType; const askConfigType = async () => { return _types.AgentConfigTypes.DOCKERIZED; }; // Questions for the gitLab configuration exports.askConfigType = askConfigType; const askForGitLabToken = async () => await (0, _basicPrompts.askInput)({ msg: gitLabPrompts.ACCESS_TOKEN, validate: (0, _basicPrompts.validateRegex)(helpers.GitLabRegexPatterns.gitLabAccessTokenRegex, helpers.invalidValueExampleErrMsg('AccessToken', 'mockToken')) }); const askForGitLabBaseURL = async () => await (0, _basicPrompts.askInput)({ msg: gitLabPrompts.BASE_URL, validate: (0, _basicPrompts.validateRegex)(helpers.GitLabRegexPatterns.gitLabBaseURLRegex, helpers.invalidValueExampleErrMsg('BaseURL', 'https://www.testdomain.com')) }); const askForGitLabRepositoryID = async () => await (0, _basicPrompts.askInput)({ msg: gitLabPrompts.REPOSITORY_ID, validate: (0, _basicPrompts.validateRegex)(helpers.GitLabRegexPatterns.gitHubRepositoryIDRegex, helpers.invalidValueExampleErrMsg('RepositoryID', '12312')) }); const askForGitLabRepositoryBranch = async () => await (0, _basicPrompts.askInput)({ msg: gitLabPrompts.REPOSITORY_BRANCH }); const askForGitLabPaths = async () => { let askPaths = true; let paths = []; console.log(_chalk.default.gray("An array of paths within the repository that the agent will gather files for looking for specs")); while (askPaths) { const path = await (0, _basicPrompts.askInput)({ msg: gitLabPrompts.PATHS, allowEmptyInput: false, validate: (0, _basicPrompts.validateRegex)(helpers.GitLabRegexPatterns.gitLabPathRegex, helpers.invalidValueExampleErrMsg('File Path', '/apis')) }); paths.push(path); askPaths = (await (0, _basicPrompts.askList)({ msg: gitLabPrompts.ENTER_MORE_PATHS, default: _types.YesNo.No, choices: _types.YesNoChoices })) === _types.YesNo.Yes; } return paths; }; const askForGitLabFilters = async () => { let askFilters = true; let filters = []; console.log(_chalk.default.gray("An array of regular expressions that a file name must match to be discovered")); while (askFilters) { const filter = await (0, _basicPrompts.askInput)({ msg: gitLabPrompts.FILTERS, allowEmptyInput: true }); if (filter.trim() != '') { filters.push(filter); askFilters = (await (0, _basicPrompts.askList)({ msg: gitLabPrompts.ENTER_MORE_FILTERS, default: _types.YesNo.No, choices: _types.YesNoChoices })) === _types.YesNo.Yes; } else { askFilters = false; } } return filters; }; const gatewayConnectivity = async installConfig => { let gitLabAgentValues = new _gitLabTemplates.GitLabAgentValues(); if (installConfig.switches.isDockerInstall) { console.log('\nCONNECTION TO GitHub API GATEWAY:'); console.log(_chalk.default.gray("The Discovery Agent needs to connect to the GitHub API Gateway to discover API's for publishing to Amplify Engage.")); gitLabAgentValues.token = await askForGitLabToken(); gitLabAgentValues.baseURL = await askForGitLabBaseURL(); gitLabAgentValues.repositoryID = await askForGitLabRepositoryID(); gitLabAgentValues.repositoryBranch = await askForGitLabRepositoryBranch(); gitLabAgentValues.paths = await askForGitLabPaths(); gitLabAgentValues.filters = await askForGitLabFilters(); } return gitLabAgentValues; }; exports.gatewayConnectivity = gatewayConnectivity; 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 startDaLinuxMsg = `\nStart the Discovery Agent on a Linux based machine`; const startDaWinMsg = `\nStart the Discovery Agent on a Windows machine`; 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}):`; } 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}`)); } }; const generateSuccessHelpMsg = installConfig => { const configType = installConfig.deploymentType; if (configType === _types.AgentConfigTypes.DOCKERIZED) { dockerSuccessMsg(installConfig); } }; const installPreprocess = async installConfig => { return installConfig; }; exports.installPreprocess = installPreprocess; const completeInstall = async installConfig => { /** * Create agent resources */ const gitLabAgentValues = installConfig.gatewayConfig; // Add final settings to gitLabAgentValues gitLabAgentValues.centralConfig = installConfig.centralConfig; gitLabAgentValues.daVersion = installConfig.daVersion; if (installConfig.switches.isDockerInstall) { if (installConfig.switches.isDaEnabled) { (0, _utils.writeTemplates)(ConfigFiles.DAEnvVars, gitLabAgentValues, helpers.gitLabDAEnvVarTemplate); } } console.log('Configuration file(s) have been successfully created.\n'); generateSuccessHelpMsg(installConfig); }; exports.completeInstall = completeInstall; const GitLabInstallMethods = exports.GitLabInstallMethods = { GetBundleType: askBundleType, GetDeploymentType: askConfigType, AskGatewayQuestions: gatewayConnectivity, InstallPreprocess: installPreprocess, FinalizeGatewayInstall: completeInstall, ConfigFiles: Object.values(ConfigFiles), GatewayDisplay: _types.GatewayTypes.GITLAB }; const testables = exports.testables = { gitLabPrompts, ConfigFiles };