@controlplane/cli
Version:
Control Plane Corporation CLI
143 lines • 5.48 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.ServiceaccountCmd = void 0;
const options_1 = require("./options");
const command_1 = require("../cli/command");
const resolver_1 = require("./resolver");
const functions_1 = require("../util/functions");
const objects_1 = require("../util/objects");
const generic_1 = require("./generic");
class ServiceaccountCmd extends command_1.Command {
constructor() {
super(...arguments);
this.command = 'serviceaccount';
this.aliases = ['sa'];
this.describe = 'Manage service accounts';
}
builder(yargs) {
const resolver = (0, resolver_1.kindResolver)('serviceaccount');
const opts = [options_1.withOrgOptions, options_1.withStandardOptions];
const commandName = 'service account';
const commandNamePlural = 'service accounts';
const commandNameA = 'a service account';
return (yargs
.demandCommand()
.version(false)
.help()
// generic
.command(new generic_1.Get(commandNamePlural, resolver, ...opts).toYargs())
.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, undefined, ...opts).toYargs())
.command(new generic_1.Delete(commandNamePlural, resolver, ...opts).toYargs())
.command(new generic_1.Eventlog(commandName, 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.Tag(commandNamePlural, resolver, ...opts).toYargs())
.command(new generic_1.Clone(commandName, resolver, ...opts).toYargs())
// specific
.command(new Create(resolver).toYargs())
.command(new AddKey(resolver).toYargs())
.command(new RemoveKey(resolver).toYargs()));
}
handle() { }
}
exports.ServiceaccountCmd = ServiceaccountCmd;
class AddKey extends command_1.Command {
constructor(resolve) {
super();
this.resolve = resolve;
this.command = 'add-key <ref>';
this.describe = 'Add a key to the reference service account';
}
builder(yargs) {
return (0, functions_1.pipe)(
//
generic_1.withSingleRef, (yargs) => {
return yargs.options({
description: {
alias: 'desc',
describe: 'Short description for the new key',
demandOption: true,
requiresArg: true,
},
});
}, options_1.withOrgOptions, options_1.withStandardOptions)(yargs);
}
async handle(args) {
let link = this.resolve.resourceLink(args.ref, this.session.context);
link += '/-addKey';
const body = {
description: args.description,
};
const response = await this.client.post(link, body);
this.session.outFormat(response);
}
}
class RemoveKey extends command_1.Command {
constructor(resolve) {
super();
this.resolve = resolve;
this.command = 'remove-key <ref>';
this.describe = 'Remove a key from the reference service account';
}
builder(yargs) {
return (0, functions_1.pipe)(
//
generic_1.withSingleRef, (yargs) => {
return yargs.options({
key: {
describe: 'Name of the key to remove. Can be repeated.',
demandOption: true,
requiresArg: true,
multiple: true,
},
});
}, options_1.withOrgOptions, options_1.withStandardOptions)(yargs);
}
async handle(args) {
const link = this.resolve.resourceLink(args.ref, this.session.context);
const body = {
'$drop/keys': (0, objects_1.toArray)(args.key),
};
const response = await this.client.patch(link, body);
this.session.outFormat(response);
}
}
class Create extends command_1.Command {
constructor(resolve) {
super();
this.resolve = resolve;
this.command = 'create';
this.describe = 'Create a new service account';
}
withCreateOptions(yargs) {
return yargs.options({
name: {
describe: 'Name of the new secret',
demandOption: true,
},
description: {
alias: 'desc',
requiresArg: true,
describe: 'Optional description, defaults to the name if not set',
},
});
}
builder(yargs) {
return (0, functions_1.pipe)(
//
this.withCreateOptions, generic_1.withTagOptions, options_1.withOrgOptions, options_1.withStandardOptions)(yargs);
}
async handle(args) {
const body = {
name: args.name,
description: args.description,
tags: (0, generic_1.fromTagOptions)(args),
};
const path = this.resolve.homeLink(this.session.context);
const data = await this.client.create(path, body);
this.session.outFormat(data);
}
}
//# sourceMappingURL=serviceaccount.js.map
;