UNPKG

@veecode-platform/safira-cli

Version:

Generate a microservice project from your spec.

162 lines (161 loc) 8.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const core_1 = require("@oclif/core"); const kong_deploy_1 = require("../../kong/kong-deploy"); const color_1 = tslib_1.__importDefault(require("@oclif/color")); const kong_mode_1 = require("../../kong/kong-mode"); const constants_1 = require("../../utils/commands/constants"); const inquirer_1 = tslib_1.__importDefault(require("inquirer")); const file_system_utils_1 = require("../../utils/file-system-utils"); const cache_manager_1 = require("../../cache/cache-manager"); const kong_plane_enum_1 = require("../../kong/kong-plane-enum"); const exit_codes_1 = require("../../command/exit-codes"); const string_utils_1 = require("../../utils/string-utils"); const array_utils_1 = require("../../utils/array-utils"); const credentials_1 = require("../../vkpr/credentials/credentials"); const credentials_dto_1 = require("../../vkpr/credentials/credentials-dto"); class KongInstall extends core_1.Command { async run() { const { args, flags } = await this.parse(KongInstall); console.log("Installing Kong..."); const domainCache = cache_manager_1.CacheManager.instance.getCache(cache_manager_1.CacheName.domain); const kongLicenseCache = cache_manager_1.CacheManager.instance.getCache(cache_manager_1.CacheName.kongLicense); const hasPostgresCredentials = credentials_1.Credentials.instance.exists(credentials_1.CredentialsKey.postgres); const answers = await inquirer_1.default.prompt([ { when: () => !flags.domain && domainCache.length > 0, type: "list", name: "domain-list", message: "Type the Kong domain:", choices: [...domainCache, { name: color_1.default.bold("Input other value."), value: "other" }], }, { when: answers => !flags.domain && (answers["domain-list"] === "other" || !answers["domain-list"]), type: "input", name: "domain-item", message: "Type the Kong domain:", default: "localhost", }, { when: !flags.secure, type: "list", name: "secure", message: "Use HTTPS?", choices: constants_1.yesNoList, default: "yes", }, { when: () => !flags.license && kongLicenseCache.length > 0, type: "list", name: "license-list", message: "Type the path to the license:", choices: [ { name: color_1.default.bold("free mode"), value: "free" }, ...kongLicenseCache, { name: color_1.default.bold("Input other value."), value: "other" }, ], }, { when: answers => !flags.license && (array_utils_1.ArrayUtils.isNullOrEmpty(kongLicenseCache) || (answers["license-list"] === "other" && answers["license-list"] !== "free")), type: "input", name: "license-item", message: "Type the path to the license:", validate: (value) => (string_utils_1.StringUtils.isNullOrEmpty(value) || file_system_utils_1.FileSystemUtils.isFile(value)) ? true : "Please type a valid path", }, { when: answers => !flags["rbac-password"] && (!string_utils_1.StringUtils.isNullOrEmpty(answers["license-item"]) || (answers["license-list"] && answers["license-list"] !== "free")), type: "input", name: "rbac-password", message: "Type the RBAC password", default: "safira1234", }, { when: answers => !flags.mode, type: "list", name: "mode", message: "Kong mode (Hybrid only available in Kong Enterprise)", choices: answers => (!string_utils_1.StringUtils.isNullOrEmpty(answers["license-item"]) || (answers["license-list"] && answers["license-list"] !== "free")) ? Object.keys(kong_mode_1.KongMode) : [kong_mode_1.KongMode.dbless, kong_mode_1.KongMode.standard], default: kong_mode_1.KongMode.dbless, }, { when: answers => !flags["postgres-password"] && !hasPostgresCredentials && [kong_mode_1.KongMode.hybrid, kong_mode_1.KongMode.standard].includes(answers.mode), type: "input", name: "postgres-password", message: "Type the Postgres password", validate: (value) => value.length >= 8 ? true : "Please type a valid password, Min length is 8.", }, { when: answers => !flags["kong-plane"] && answers.mode === kong_mode_1.KongMode.hybrid, type: "list", name: "kong-plane", message: "Select the plane to install", choices: Object.keys(kong_plane_enum_1.KongPlaneEnum), }, { when: answers => !flags["kong-cp-url"] && answers["kong-plane"] === kong_plane_enum_1.KongPlaneEnum.data, type: "input", name: "kong-cp-url", message: "Kong Control Plane", default: "kong-kong-cluster.vkpr.svc.cluster.local:8005", }, { when: answers => !flags["kong-telemetry-url"] && answers["kong-plane"] === kong_plane_enum_1.KongPlaneEnum.data, type: "input", name: "kong-telemetry-url", message: "Kong Telemetry Endpoint", default: "kong-kong-clustertelemetry.vkpr.svc.cluster.local:8006", }, { when: !flags.HA, type: "list", name: "HA", message: "Use High Availability (HA) mode?", choices: constants_1.yesNoList, }, ]); if (answers["domain-item"]) cache_manager_1.CacheManager.instance.addItem(cache_manager_1.CacheName.domain, answers["domain-item"]); if (!string_utils_1.StringUtils.isNullOrEmpty(answers["license-item"])) cache_manager_1.CacheManager.instance.addItem(cache_manager_1.CacheName.kongLicense, file_system_utils_1.FileSystemUtils.fullPath(answers["license-item"])); if (!string_utils_1.StringUtils.isNullOrEmpty(answers["postgres-password"])) await credentials_1.Credentials.instance.setCredential(new credentials_dto_1.PostgresCredential(answers["postgres-password"])); try { await new kong_deploy_1.KongDeployImpl().deploy({ domain: answers["domain-item"] || flags.domain, secure: (flags.secure || answers.secure) === "yes", mode: flags.mode || answers.mode || kong_mode_1.KongMode.dbless, license: file_system_utils_1.FileSystemUtils.fullPath(flags.license || answers["license-item"]), HA: (flags.HA || answers.HA) === "yes", rbacPassword: flags["rbac-password"] || answers["rbac-password"], kongPlane: flags["kong-plane"] || answers["kong-plane"], kongTelemetryUrl: flags["kong-telemetry-url"] || answers["kong-telemetry-url"], kongCpUrl: flags["kong-cp-url"] || answers["kong-cp-url"], }); } catch (error) { this.log(color_1.default.red(error.message)); process.exit(exit_codes_1.ExitCode.operationNotPermitted); } } } exports.default = KongInstall; KongInstall.description = "Install Kong in your k8s cluster"; KongInstall.hidden = true; KongInstall.examples = [ "<%= config.bin %> <%= command.id %>", ]; KongInstall.flags = { help: core_1.Flags.help({}), domain: core_1.Flags.string({ description: "domain" }), secure: core_1.Flags.string({ description: "secure", options: constants_1.yesNoList }), mode: core_1.Flags.string({ description: "Kong mode (Hybrid only available in Kong Enterprise)", options: Object.keys(kong_mode_1.KongMode) }), license: core_1.Flags.string({ description: "Path to license file" }), HA: core_1.Flags.string({ description: "Use High Availability mode", options: constants_1.yesNoList }), "rbac-password": core_1.Flags.string({ description: "RBAC password" }), "kong-plane": core_1.Flags.string({ description: "Specifies the Plane to install on Hybrid Mode", options: Object.keys(kong_plane_enum_1.KongPlaneEnum) }), "kong-telemetry-url": core_1.Flags.string({ description: "Specifies which telemetry endpoint" }), "kong-cp-url": core_1.Flags.string({ description: "Specifies which Kong CP to point at" }), "postgres-password": core_1.Flags.string({ description: "Postgres password if in Hybrid or Standard Mode" }), }; KongInstall.args = [];