UNPKG

@controlplane/cli

Version:

Control Plane Corporation CLI

118 lines 4.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CreateIdentity = exports.IdentityCmd = void 0; const options_1 = require("./options"); const command_1 = require("../cli/command"); const resultFetcher_1 = require("../rest/resultFetcher"); const resolver_1 = require("./resolver"); const functions_1 = require("../util/functions"); const generic_1 = require("./generic"); class IdentityCmd extends command_1.Command { constructor() { super(...arguments); this.command = 'identity'; this.aliases = ['id']; this.describe = 'Manage identities within a global virtual cloud'; } builder(yargs) { const resolver = (0, resolver_1.kindResolver)('identity'); const schema = { rels: ['gvc'], }; const opts = [options_1.withGvcOptions, options_1.withStandardOptions]; const commandName = 'identity'; const commandNamePlural = 'identities'; const commandNameA = 'an identity'; return (yargs .demandCommand() .version(false) .help() // generic .command(new generic_1.Edit(commandName, resolver, ...opts).toYargs()) .command(new generic_1.Patch(commandName, resolver, ...opts).toYargs()) .command(new generic_1.Query(commandNamePlural, resolver, schema, ...opts).toYargs()) .command(new generic_1.Delete(commandNamePlural, resolver, ...opts).toYargs()) .command(new generic_1.Eventlog(commandName, resolver, ...opts).toYargs()) .command(new generic_1.Tag(commandNamePlural, resolver, ...opts).toYargs()) .command(new generic_1.ListPermissions(commandNameA, resolver, ...opts).toYargs()) .command(new generic_1.ViewAccessReport(commandName, resolver, ...opts).toYargs()) .command(new generic_1.Update(commandName, resolver, [ { path: 'description', }, { path: 'tags.<key>', }, ], ...opts).toYargs()) // specific .command(new GetIdentity(resolver, ...opts).toYargs()) .command(new CreateIdentity(resolver).toYargs())); } handle() { } } exports.IdentityCmd = IdentityCmd; class GetIdentity extends generic_1.Get { constructor(resolve, ...funcs) { super('identities', resolve, ...funcs); } async list(args) { let link; if (args.allGvcs) { link = this.resolve.homeLink(this.session.context); } else { link = this.resolve.parentLink(this.session.context); } const body = await this.client.get(link); await (0, resultFetcher_1.fetchPages)(this.client, this.session.format.max, body); this.session.outFormat(body); } builder(yargs) { return (0, functions_1.pipe)(super.builder.bind(this), (yargs) => { return yargs.options({ 'all-gvcs': { boolean: true, describe: 'Show identities from all gvcs in the org', }, }); })(yargs); } } class CreateIdentity extends command_1.Command { constructor(resolve) { super(); this.resolve = resolve; this.command = 'create'; this.describe = 'Create a new identity'; } builder(yargs) { return (0, functions_1.pipe)( // (yargs) => { return yargs.options({ name: { describe: 'Name of the new identity', requiresArg: true, demandOption: true, }, description: { alias: 'desc', describe: 'Optional description, defaults to the name if not set', }, }); }, generic_1.withTagOptions, options_1.withAllOptions)(yargs); } async handle(args) { var _a; let link = this.resolve.parentLink(this.session.context); const req = { name: args.name, description: (_a = args.description) !== null && _a !== void 0 ? _a : args.name, tags: (0, generic_1.fromTagOptions)(args), }; const body = await this.client.create(link, req); this.session.outFormat(body); } } exports.CreateIdentity = CreateIdentity; //# sourceMappingURL=identity.js.map