UNPKG

@axway/axway-central-cli

Version:

Manage APIs, services and publish to the Amplify Marketplace

102 lines (100 loc) 4.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setCommand = void 0; var _cliKit = require("cli-kit"); var _fsExtra = require("fs-extra"); var _set = _interopRequireDefault(require("lodash/set")); var _types = require("../../common/types"); var _utils = require("../../common/utils"); var _common = require("./common"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } const { log } = (0, _cliKit.snooplogg)('engage: config: set'); const action = async ({ argv, console }) => { var _argv$name; const isValidRootConfig = argv.baseUrl || argv.clientId || argv.region || argv.platform || argv.apicDeployment; const isValidExtension = ((_argv$name = argv.name) === null || _argv$name === void 0 ? void 0 : _argv$name.startsWith(`${_types.ConfigTypes.EXTENSIONS}.`)) && argv.value; if (!isValidRootConfig && !isValidExtension) { log((0, _cliKit.chalk)`{magenta Allowed engage config values weren't provided. Exiting...}`); throw Error(` Allowed engage config values weren't provided`); } if (argv.clientId) { log(`Unsupported values received`); throw Error(`"client-id" configuration is no longer supported, please check the latest docs for updated examples.`); } try { const config = await (0, _common.readConfig)(); if (isValidExtension) { log(`Writing ${_types.ConfigTypes.EXTENSIONS}`); (0, _set.default)(config, argv.name, argv.value); } if (argv.baseUrl) { log(`Writing ${_types.ConfigTypes.BASE_URL}`); config[_types.ConfigTypes.BASE_URL] = argv.baseUrl; } if (argv.region) { // verify passed value const parsedValue = String(argv.region).toUpperCase(); if (!(parsedValue in _types.Regions)) { throw Error(`"--region" value is not correct, please provide one of: ${Object.values(_types.Regions).sort().join(', ')}. For example: "axway engage config set --region=US"`); } log(`Writing ${_types.ConfigTypes.REGION}`); config[_types.ConfigTypes.REGION] = parsedValue; } if (argv.platform) { const parsedValue = String(argv.platform).toLowerCase(); if (!(parsedValue in _types.Platforms)) { throw Error(`"--platform" value is not correct, please provide one of: ${Object.values(_types.Platforms).sort().join(', ')}. For example: "axway engage config set --platform=staging"`); } log(`Writing ${_types.ConfigTypes.PLATFORM}`); config[_types.ConfigTypes.PLATFORM] = parsedValue; } if (argv.apicDeployment) { log(`Writing ${_types.ConfigTypes.APIC_DEPLOYMENT}`); if (!Object.values(_types.APICDeployments).includes(argv.apicDeployment)) { throw Error(`"--apic-deployment" value is not correct, please provide one of: ${Object.values(_types.APICDeployments).sort().join(', ')}. For example: "axway engage config set --apic-deployment=staging"`); } config[_types.ConfigTypes.APIC_DEPLOYMENT] = argv.apicDeployment; } // check for axway managed flag if (argv.axwayManaged) { log(`Writing ${_types.ConfigTypes.AXWAY_MANAGED}`); config[_types.ConfigTypes.AXWAY_MANAGED] = true; } await (0, _fsExtra.outputJson)(_utils.configFile, config, { spaces: '\t' }); } catch (e) { console.error(`Couldn't save config in ${_utils.configFile}`); throw e; } }; const setCommand = exports.setCommand = { action, desc: 'Set Engage CLI settings', options: { // TODO: client-id is no longer supported keeping for some time for validation purposes // config rework is going to happen: https://jira.axway.com/browse/APIGOV-19737 '--client-id [value]': { hidden: true, descr: "Set your DevOps account's client ID" }, '--region [value]': 'Set your region, one of: US or EU (US region is used by default if nothing set).', '--base-url [value]': { hidden: true }, '--apic-deployment [value]': { hidden: true }, '--axway-managed': { hidden: true } }, args: ['[name]', '[value]'] };