@axway/axway-central-cli
Version:
Manage APIs, services and publish to the Amplify Marketplace
109 lines (107 loc) • 4.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.create = void 0;
var _snooplogg = _interopRequireDefault(require("snooplogg"));
var _ApiServerClient = require("../../common/ApiServerClient");
var _DefinitionsManager = require("../../common/DefinitionsManager");
var _Renderer = _interopRequireDefault(require("../../common/Renderer"));
var _types = require("../../common/types");
var _utils = require("../../common/utils");
var _environment = require("./environment");
var _serviceAccount = require("./serviceAccount");
var _agentResource = require("./agentResource");
var _basicPrompts = require("../../common/basicPrompts");
var _chalk = _interopRequireDefault(require("chalk"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const {
log
} = (0, _snooplogg.default)('engage: create');
const action = async ({
argv,
console
}) => {
const {
baseUrl,
account,
file,
output,
region,
cache,
yes
} = argv;
let commandIsSuccessful = false;
// need to verify args here since if "-f" is required
// cli-kit is also enforcing it on sub-commands
log(`verifying args`);
if (!file) throw new Error('To create resources from a file, please provide -f, --file [path] option');
log(`verifying file: ${file}`);
(0, _utils.verifyFile)(file);
let results = {
success: [],
error: [],
warning: []
};
const render = new _Renderer.default(console, output).startSpin('Creating resource(s)');
const client = new _ApiServerClient.ApiServerClient({
baseUrl,
account,
region,
useCache: cache
});
const defsManager = new _DefinitionsManager.DefinitionsManager(client);
log(`executing api calls`);
try {
await defsManager.init();
log(`loading and verifying specs`);
const {
docs,
isMissingName
} = await (0, _utils.loadAndVerifySpecs)(file, defsManager.getAllKindsList());
if (!yes && isMissingName) {
render.stopSpin();
if ((await (0, _basicPrompts.askList)({
msg: `As your file contains resources with missing logical names, their logical names will be autogenerated. \nRun ${_chalk.default.cyan('axway engage create -f <filepath> -o [yaml|json] -y > <output filepath>')} to capture the resource(s) with the autogenerated logical name(s) so you can use them again. \nNOTE: To suppress this prompt in the future, please use the '-y' flag. \nWould you like to continue *without* capturing the resource names in a new file?`,
choices: _types.YesNoChoices,
default: _types.YesNo.Yes
})) === _types.YesNo.No) process.exit(1);
render.startSpin('Creating resource(s)');
}
const sortedKindsMap = defsManager.getSortedKindsMap();
results = await client.bulkCreate(docs, sortedKindsMap);
render.bulkResult(results, 'has successfully been created.');
commandIsSuccessful = !results.error.length;
} catch (e) {
log('command error', e);
// if some calls have been completed, rendering the result
if (results.success.length || results.error.length) render.bulkResult(results, 'has successfully been created.');
render.anyError(e);
} finally {
log(`command finished, success = ${commandIsSuccessful}`);
render.stopSpin();
!commandIsSuccessful && process.exit(1);
}
};
const create = exports.create = {
action,
commands: {
'service-account': _serviceAccount.serviceAccount,
environment: _environment.environment,
'agent-resource': _agentResource.agentResource
},
desc: 'Create one or more resources from a file or stdin',
options: {
..._types.commonCmdArgsDescription,
'-o, --output [value]': {
desc: `Additional output formats. One of: ${_types.OutputTypes.yaml} | ${_types.OutputTypes.json}`,
type: 'string'
},
// TODO: -f is propagated to sub commands is there any way to remove it?
'-f, --file [path]': {
desc: `Filename to use to create the resource`,
type: 'string'
},
'-y, --yes': 'Automatically reply "yes" to any command prompts.'
}
};