@codiac.io/codiac-cli 1.2.264 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/README.md +1 -1
  2. package/dist/apis/codiac-api/common/api-client-base.d.ts +21 -7
  3. package/dist/apis/codiac-api/common/api-client-base.js +8 -6
  4. package/dist/apis/codiac-api/common/api-client-base.js.map +1 -1
  5. package/dist/apis/codiac-api/gen/client.d.ts +268 -198
  6. package/dist/apis/codiac-api/gen/client.js +2464 -970
  7. package/dist/apis/codiac-api/gen/client.js.map +1 -1
  8. package/dist/apis/codiac-api/gen/contracts.d.ts +171 -33
  9. package/dist/apis/codiac-api/gen/contracts.js +72 -76
  10. package/dist/apis/codiac-api/gen/contracts.js.map +1 -1
  11. package/dist/apis/codiac-relay/gen/client.d.ts +2 -2
  12. package/dist/apis/codiac-relay/gen/client.js.map +1 -1
  13. package/dist/cli-common/command-base.d.ts +10 -0
  14. package/dist/cli-common/command-base.js +21 -0
  15. package/dist/cli-common/command-base.js.map +1 -1
  16. package/dist/command-base-enterprise.d.ts +11 -11
  17. package/dist/command-base-enterprise.js +83 -60
  18. package/dist/command-base-enterprise.js.map +1 -1
  19. package/dist/command-base-exec-tenant.d.ts +21 -0
  20. package/dist/command-base-exec-tenant.js +72 -0
  21. package/dist/command-base-exec-tenant.js.map +1 -0
  22. package/dist/command-base-tenantless.d.ts +0 -5
  23. package/dist/command-base-tenantless.js +0 -11
  24. package/dist/command-base-tenantless.js.map +1 -1
  25. package/dist/commands/asset/deploy.js +1 -0
  26. package/dist/commands/asset/deploy.js.map +1 -1
  27. package/dist/commands/auth/cabinet/allow.d.ts +49 -0
  28. package/dist/commands/auth/cabinet/allow.js +155 -0
  29. package/dist/commands/auth/cabinet/allow.js.map +1 -0
  30. package/dist/commands/auth/cabinet/allowed.d.ts +44 -0
  31. package/dist/commands/auth/cabinet/allowed.js +187 -0
  32. package/dist/commands/auth/cabinet/allowed.js.map +1 -0
  33. package/dist/commands/auth/enterprise/allow/onEnvironments.d.ts +41 -0
  34. package/dist/commands/auth/enterprise/allow/onEnvironments.js +146 -0
  35. package/dist/commands/auth/enterprise/allow/onEnvironments.js.map +1 -0
  36. package/dist/commands/auth/enterprise/allow.d.ts +43 -0
  37. package/dist/commands/auth/enterprise/allow.js +140 -0
  38. package/dist/commands/auth/enterprise/allow.js.map +1 -0
  39. package/dist/commands/auth/enterprise/allowed.d.ts +40 -0
  40. package/dist/commands/auth/enterprise/allowed.js +171 -0
  41. package/dist/commands/auth/enterprise/allowed.js.map +1 -0
  42. package/dist/commands/auth/environment/allow/onCabinets.d.ts +43 -0
  43. package/dist/commands/auth/environment/allow/onCabinets.js +156 -0
  44. package/dist/commands/auth/environment/allow/onCabinets.js.map +1 -0
  45. package/dist/commands/auth/environment/allow.d.ts +46 -0
  46. package/dist/commands/auth/environment/allow.js +148 -0
  47. package/dist/commands/auth/environment/allow.js.map +1 -0
  48. package/dist/commands/auth/environment/allowed.d.ts +42 -0
  49. package/dist/commands/auth/environment/allowed.js +182 -0
  50. package/dist/commands/auth/environment/allowed.js.map +1 -0
  51. package/dist/commands/auth/register.d.ts +32 -0
  52. package/dist/commands/auth/register.js +170 -0
  53. package/dist/commands/auth/register.js.map +1 -0
  54. package/dist/commands/auth/role/allowed.d.ts +33 -0
  55. package/dist/commands/auth/role/allowed.js +135 -0
  56. package/dist/commands/auth/role/allowed.js.map +1 -0
  57. package/dist/commands/auth/role/assign.d.ts +26 -0
  58. package/dist/commands/auth/role/assign.js +92 -0
  59. package/dist/commands/auth/role/assign.js.map +1 -0
  60. package/dist/commands/auth/role/create.d.ts +24 -0
  61. package/dist/commands/auth/role/create.js +90 -0
  62. package/dist/commands/auth/role/create.js.map +1 -0
  63. package/dist/commands/auth/role/delete.d.ts +28 -0
  64. package/dist/commands/auth/role/delete.js +119 -0
  65. package/dist/commands/auth/role/delete.js.map +1 -0
  66. package/dist/commands/auth/role/list.d.ts +26 -0
  67. package/dist/commands/auth/role/list.js +108 -0
  68. package/dist/commands/auth/role/list.js.map +1 -0
  69. package/dist/commands/auth/role/unassign.d.ts +26 -0
  70. package/dist/commands/auth/role/unassign.js +92 -0
  71. package/dist/commands/auth/role/unassign.js.map +1 -0
  72. package/dist/commands/auth/user/invite.d.ts +24 -0
  73. package/dist/commands/auth/user/invite.js +105 -0
  74. package/dist/commands/auth/user/invite.js.map +1 -0
  75. package/dist/commands/auth/user/list.d.ts +26 -0
  76. package/dist/commands/auth/user/list.js +118 -0
  77. package/dist/commands/auth/user/list.js.map +1 -0
  78. package/dist/commands/cabinet/create.d.ts +1 -1
  79. package/dist/commands/cabinet/create.js +28 -20
  80. package/dist/commands/cabinet/create.js.map +1 -1
  81. package/dist/commands/cabinet/list.d.ts +1 -0
  82. package/dist/commands/cabinet/list.js +9 -1
  83. package/dist/commands/cabinet/list.js.map +1 -1
  84. package/dist/commands/cabinet/obliterate.js +39 -34
  85. package/dist/commands/cabinet/obliterate.js.map +1 -1
  86. package/dist/commands/config/deploy.js +5 -2
  87. package/dist/commands/config/deploy.js.map +1 -1
  88. package/dist/commands/enterprise/create.js +1 -1
  89. package/dist/commands/enterprise/create.js.map +1 -1
  90. package/dist/commands/environment/create.d.ts +1 -0
  91. package/dist/commands/environment/create.js +4 -2
  92. package/dist/commands/environment/create.js.map +1 -1
  93. package/dist/commands/secretStore/list.js +2 -2
  94. package/dist/commands/secretStore/list.js.map +1 -1
  95. package/dist/commands/tenant/create.d.ts +0 -2
  96. package/dist/commands/tenant/create.js +0 -33
  97. package/dist/commands/tenant/create.js.map +1 -1
  98. package/dist/commands/tenant/switch.d.ts +0 -2
  99. package/dist/commands/tenant/switch.js +0 -33
  100. package/dist/commands/tenant/switch.js.map +1 -1
  101. package/dist/commands/whoami.d.ts +3 -1
  102. package/dist/commands/whoami.js +8 -2
  103. package/dist/commands/whoami.js.map +1 -1
  104. package/dist/ops/data/cli-context-repo.js +2 -2
  105. package/dist/ops/data/cli-context-repo.js.map +1 -1
  106. package/dist/relay/relay-container.js +1 -1
  107. package/dist/uilogic/rootmap-ui-utils.js +38 -8
  108. package/dist/uilogic/rootmap-ui-utils.js.map +1 -1
  109. package/dist/uilogic/tenant-contextualizer.js +8 -2
  110. package/dist/uilogic/tenant-contextualizer.js.map +1 -1
  111. package/dist/user-context-loader.d.ts +1 -1
  112. package/dist/user-context-loader.js +3 -2
  113. package/dist/user-context-loader.js.map +1 -1
  114. package/oclif.manifest.json +1597 -93
  115. package/package.json +4 -4
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const path = require("path");
5
+ const core_1 = require("@oclif/core");
6
+ const _ = require("lodash");
7
+ const codiac_api_1 = require("../../apis/codiac-api");
8
+ const cli_common_1 = require("../../cli-common");
9
+ const log4js_logger_1 = require("../../log4js-logger");
10
+ const read_stdin_1 = require("../../read-stdin");
11
+ const config_ui_utils_1 = require("../../uilogic/config-ui-utils");
12
+ const user_context_loader_1 = require("../../user-context-loader");
13
+ class AuthRegister extends cli_common_1.commandBase {
14
+ get codiacApiUrl() {
15
+ var _a, _b, _c;
16
+ if (this.__codiacApiUrl === undefined) {
17
+ this.__codiacApiUrl = (_c = (_b = (_a = this.localConfig) === null || _a === void 0 ? void 0 : _a.apiUrl) !== null && _b !== void 0 ? _b : this._cliCfg.codiacApiBaseUrl) !== null && _c !== void 0 ? _c : codiac_api_1.CodiacClient.DEFAULT_API_URL;
18
+ }
19
+ return this.__codiacApiUrl; // <--- wtf this is still needed, but we just ensured its not undefined ??
20
+ }
21
+ /** TODO: Get this out of the CLI. Any calls to the codiac api should be made from the relay. */
22
+ get _codiacApi() {
23
+ if (this.__codiacApi === undefined) {
24
+ this.__codiacApi = this.ioc.get(codiac_api_1.CodiacClient);
25
+ }
26
+ return this.__codiacApi;
27
+ }
28
+ bootstrap() {
29
+ if (AuthRegister.isBootstrapped !== true) {
30
+ cli_common_1.commandBase.bootstrap(this.ioc, this.config, false);
31
+ // TODO: move this to commandBase
32
+ log4js_logger_1.Log4jsLogger.bootstrap(this.ioc, {
33
+ appenders: {
34
+ "console": { type: "console" },
35
+ "applog": { type: "file", maxLogSize: "2M", backups: 3, compress: false, keepFileExt: true, filename: path.posix.join(this.localConfigPath, "logs", "cli.log") },
36
+ "errlog": { type: "file", maxLogSize: "2M", backups: 3, compress: false, keepFileExt: true, filename: path.posix.join(this.localConfigPath, "logs", "cli-error.log") }
37
+ },
38
+ categories: {
39
+ default: { appenders: ["applog"], level: "trace" },
40
+ errors: { appenders: ["errlog"], level: "error" },
41
+ console: { appenders: ["console"], level: "off" }
42
+ }
43
+ });
44
+ codiac_api_1.CodiacClient.bootstrap();
45
+ this.ioc.bind(codiac_api_1.CodiacClient).toDynamicValue(() => codiac_api_1.CodiacClient.create(this.logger, this.codiacApiUrl)); //
46
+ AuthRegister.isBootstrapped = true;
47
+ }
48
+ }
49
+ run() {
50
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
51
+ this.bootstrap();
52
+ try {
53
+ let [partial, interactionMode, takeDefaults] = yield this.captureArgs();
54
+ let candidate = yield this.buildCandidate_silently(partial);
55
+ yield this.execute(candidate);
56
+ }
57
+ catch (err) {
58
+ this.handleError(err);
59
+ }
60
+ });
61
+ }
62
+ captureArgs() {
63
+ var _a, _b;
64
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
65
+ const { args, flags } = yield this.parse(AuthRegister);
66
+ let partial = {
67
+ newUser: true
68
+ };
69
+ if (flags.email)
70
+ partial.userName = flags.email;
71
+ if (flags.company)
72
+ partial.tenantName = flags.company;
73
+ if (flags.companyCode)
74
+ partial.tenantCode = flags.companyCode;
75
+ if (flags.firstName)
76
+ partial.firstName = flags.firstName;
77
+ if (flags.lastName)
78
+ partial.lastName = flags.lastName;
79
+ if (flags.passwordIn === true) {
80
+ partial.password = yield (0, read_stdin_1.default)();
81
+ }
82
+ else {
83
+ if (flags.password)
84
+ partial.password = flags.password;
85
+ }
86
+ // this is how csp/login does it...
87
+ // let clientSecret = await readStdin();
88
+ // if (_.isEmpty(clientSecret) && (flags.silent !== true)) {
89
+ // clientSecret = await this._ui.promptPassword("clientSecret", "Client Secret: ");
90
+ // }
91
+ // ---------------------------------------------------------------
92
+ // TODO: move everything from here down into the base class
93
+ // ---------------------------------------------------------------
94
+ const interactionMode = (this.pipedInput) ? config_ui_utils_1.InteractionModes.silent : (_b = (_a = undefined !== null && undefined !== void 0 ? undefined : (flags.echo ? config_ui_utils_1.InteractionModes.echo : undefined)) !== null && _a !== void 0 ? _a : (flags["to-script"] ? config_ui_utils_1.InteractionModes.toscript : undefined)) !== null && _b !== void 0 ? _b : (flags.silent ? config_ui_utils_1.InteractionModes.silent : undefined);
95
+ const takeDefaults = flags['take-defaults'];
96
+ return [partial, interactionMode, takeDefaults];
97
+ });
98
+ }
99
+ buildCandidate_silently(partial) {
100
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
101
+ // Assemble candidate
102
+ if (partial.userName == undefined || _.isEmpty(partial.userName))
103
+ throw new Error("You must provide a valid username");
104
+ if (partial.password == undefined || _.isEmpty(partial.password))
105
+ throw new Error("You must provide a valid password");
106
+ if (partial.tenantName == undefined || _.isEmpty(partial.tenantName))
107
+ throw new Error("You must provide a tenant name");
108
+ let candidate = {
109
+ newUser: true,
110
+ userName: partial.userName,
111
+ password: partial.password,
112
+ tenantName: partial.tenantName
113
+ };
114
+ if (partial.firstName != undefined || !_.isEmpty(partial.firstName))
115
+ candidate.firstName = partial.firstName;
116
+ if (partial.lastName != undefined || !_.isEmpty(partial.lastName))
117
+ candidate.lastName = partial.lastName;
118
+ return candidate;
119
+ });
120
+ }
121
+ execute(candidate) {
122
+ var _a, _b;
123
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
124
+ try {
125
+ let result = yield this._codiacApi.Auth.TenantRegistration(candidate);
126
+ if (result.error) {
127
+ throw result.error;
128
+ }
129
+ else if (result.output == undefined || result.output.Users == undefined || result.output.Users.length == 0) {
130
+ throw new Error("Registration failed without explicit error: ".concat((_a = result.message) !== null && _a !== void 0 ? _a : "no details provided."));
131
+ }
132
+ else if (result.success) {
133
+ const newTenant = result.output;
134
+ const newUser = result.output.Users[0];
135
+ let token = this._codiacApi.authToken; // <-- the gets overwritten with the return token. Assertion ok here bc successful
136
+ let exp = this._codiacApi.Auth.extractTokenExpiration(token);
137
+ let roles = (_b = newUser.roles) === null || _b === void 0 ? void 0 : _b.map(r => r.name);
138
+ // TODO: log the current user in.
139
+ let userContextRepo = new user_context_loader_1.UserContextManager(this._codiacApi, this.logger);
140
+ let newContext = yield userContextRepo.saveToUserContext(undefined, newUser.login, token, newUser.tenantCode, exp, roles);
141
+ this._ui.userMessage(this._styler.colorGood("Successfully registered!").concat(" user: ", newUser.login, " is the administrator for ", newTenant.name, " [", newTenant.code, "]"));
142
+ }
143
+ }
144
+ catch (err) {
145
+ this.handleError(err);
146
+ }
147
+ });
148
+ }
149
+ }
150
+ exports.default = AuthRegister;
151
+ AuthRegister.description = 'Create your own user account.';
152
+ AuthRegister.examples = [
153
+ '<%= config.bin %> <%= command.id %>',
154
+ ];
155
+ AuthRegister.flags = {
156
+ email: core_1.Flags.string({ char: 'u', description: "Must be a valid email. This will be your login/username on Codiac." }),
157
+ password: core_1.Flags.string({ char: 'p', exclusive: ["passwordIn"], description: "password on Codiac in clear text. NOT RECOMMENDED: use the `passwordIn` argument instead to transmit your password via stdin." }),
158
+ passwordIn: core_1.Flags.boolean({ char: 'i', exclusive: ["password"], description: "Reads the password directly from the standard input stream. Enables users to avoid explicitly rendering it in a command string. eg: `cat mypass.txt | cod register -u joecool --passwordIn`. Invokes `--silent` mode, so interaction will be disabled." }),
159
+ company: core_1.Flags.string({ char: 'c', description: "Human readable friendly title for the organization (eg: 'ACME Anvils, Inc.'). NOT used for system identification. NOTE: Users can belong to more than one organization; this one shall simply be the first for this user." }),
160
+ companyCode: core_1.Flags.string({ description: "(optional) Unique identifier for the organization within Codiac (eg: 'acme'). This value IS used for system identification, and must be unique across all of Codiac. This command will fail if this given company code is already taken (Must be 3 to 9 alphanumeric characters, no spaces or special characters)." }),
161
+ firstName: core_1.Flags.string({ char: 'f', description: "(optional; you can edit this later)" }),
162
+ lastName: core_1.Flags.string({ char: 'l', description: "(optional; you can edit this later)" }),
163
+ // TODO: Move these into the base class
164
+ silent: core_1.Flags.boolean({ exclusive: ["echo", "to-script"], description: 'Non-Interactive mode; executes without any user interaction and fails on any missing or invalid arguments.' }),
165
+ echo: core_1.Flags.boolean({ exclusive: ["to-script", "silent"], description: 'Echo interaction mode; renders the equivalent non-interactive cli command for future use before final execution.' }),
166
+ "to-script": core_1.Flags.boolean({ exclusive: ["echo", "silent"], description: 'Toscript interaction mode; renders the equivalent non-interactive cli command WITHOUT any execution.' }),
167
+ "take-defaults": core_1.Flags.boolean({ exclusive: ["silent"], description: "Setting this to true prevents prompting for confirmation on parameters that were passed in or were automatically set to default values (Irrelevant in --silent mode). This behavior does NOT apply to scenarios that the command needs to override invalid user input; such cases will always prompt for confirmation. eg: when no argument was provided for file or type, and only one exists, the system will render the autoselected file unless this flag is set." })
168
+ };
169
+ AuthRegister.args = {};
170
+ //# sourceMappingURL=register.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.js","sourceRoot":"","sources":["../../../src/commands/auth/register.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,sCAAkD;AAClD,4BAA4B;AAC5B,sDAAoD;AAEpD,iDAA8C;AAC9C,uDAAkD;AAClD,iDAAwC;AACxC,mEAAgE;AAChE,mEAA+D;AAE/D,MAAqB,YAAa,SAAQ,wBAAW;IA6BnD,IAAc,YAAY;;QACxB,IAAI,IAAI,CAAC,cAAc,KAAK,SAAS,EAAE;YACrC,IAAI,CAAC,cAAc,GAAG,MAAA,MAAA,MAAA,IAAI,CAAC,WAAW,0CAAE,MAAM,mCAAI,IAAI,CAAC,OAAO,CAAC,gBAAgB,mCAAI,yBAAY,CAAC,eAAe,CAAC;SACjH;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kHAAkH,EAAE,CAAC;IAC5L,WAAW,EAAE,YAAK,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,WAAW,EAAE,sGAAsG,EAAE,CAAC;IAClL,eAAe,EAAE,YAAK,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC,QAAQ,CAAC,EAAE,WAAW,EAAE,ycAAyc,EAAE,CAAC;CAClhB,CAAA;AAEM,iBAAI,GAAG,EACb,CAAA"}
@@ -0,0 +1,33 @@
1
+ import { RootMap } from '../../../apis/codiac-api/contracts';
2
+ import { CommandBaseExec } from '../../../command-base-exec';
3
+ import { AtLeast } from '@codiac.io/codiac-common/contracts';
4
+ import { InteractionModes } from '../../../uilogic/config-ui-utils';
5
+ export type IRoleAccessSelector = {
6
+ id?: string;
7
+ name: string;
8
+ enterprise: string;
9
+ rootMap: RootMap;
10
+ };
11
+ export default class AuthRoleAllowed extends CommandBaseExec<IRoleAccessSelector> {
12
+ static description: string;
13
+ static aliases: never[];
14
+ static examples: string[];
15
+ static flags: {
16
+ id: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
17
+ enterprise: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
18
+ silent: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
19
+ echo: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
20
+ "to-script": import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
21
+ "take-defaults": import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
22
+ };
23
+ static args: {
24
+ name: import("@oclif/core/lib/interfaces/parser").Arg<string | undefined, Record<string, unknown>>;
25
+ };
26
+ protected adminOnly: boolean;
27
+ captureArgs(enterpriseCode: string): Promise<[AtLeast<IRoleAccessSelector, "enterprise">, (InteractionModes | undefined), boolean]>;
28
+ buildCandidate_silently(partial: AtLeast<IRoleAccessSelector, "enterprise">, rootMap: RootMap): Promise<IRoleAccessSelector | undefined>;
29
+ buildCandidate_interactively(partial: AtLeast<IRoleAccessSelector, "enterprise">, rootMap: RootMap, takeDefaults: boolean): Promise<IRoleAccessSelector | undefined>;
30
+ buildCommandString(candidate: IRoleAccessSelector, cmd: string[]): string[];
31
+ executeTask(candidate: IRoleAccessSelector): Promise<void>;
32
+ private createRoleAccessEmbellisher;
33
+ }
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const core_1 = require("@oclif/core");
5
+ const render = require("../../../uilogic/render-methods");
6
+ const command_base_exec_1 = require("../../../command-base-exec");
7
+ const config_ui_utils_1 = require("../../../uilogic/config-ui-utils");
8
+ class AuthRoleAllowed extends command_base_exec_1.CommandBaseExec {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.adminOnly = true;
12
+ }
13
+ captureArgs(enterpriseCode) {
14
+ var _a, _b;
15
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
16
+ const { args, flags } = yield this.parse(AuthRoleAllowed);
17
+ let partial = {
18
+ enterprise: enterpriseCode
19
+ };
20
+ if (args.name && flags.id) {
21
+ throw new Error("You must specify either the role name argument or the --id flag, not both.");
22
+ }
23
+ if (args.name)
24
+ partial.name = args.name;
25
+ if (flags.id)
26
+ partial.id = flags.id;
27
+ // ---------------------------------------------------------------
28
+ // TODO: move everything from here down into the base class
29
+ // ---------------------------------------------------------------
30
+ const interactionMode = (this.pipedInput) ? config_ui_utils_1.InteractionModes.silent : (_b = (_a = undefined !== null && undefined !== void 0 ? undefined : (flags.echo ? config_ui_utils_1.InteractionModes.echo : undefined)) !== null && _a !== void 0 ? _a : (flags["to-script"] ? config_ui_utils_1.InteractionModes.toscript : undefined)) !== null && _b !== void 0 ? _b : (flags.silent ? config_ui_utils_1.InteractionModes.silent : undefined);
31
+ const takeDefaults = flags['take-defaults'];
32
+ return [partial, interactionMode, takeDefaults];
33
+ });
34
+ }
35
+ // /** Throws on invalid */
36
+ // private validate(partial: Partial<IAuthRoleDef>): void {
37
+ // if (partial.name == undefined || _.isEmpty(partial.name)) throw new Error("Missing name");
38
+ // let rxName = /^[a-zA-Z][a-zA-Z0-9-]{2,50}$/;
39
+ // if (!rxName.test(partial.name)) throw new Error("Invalid name: must be 3- to 50-character string of alphanumerics and hyphens, starting with a letter.");
40
+ // }
41
+ buildCandidate_silently(partial, rootMap) {
42
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
43
+ if (partial.id == undefined && partial.name == undefined)
44
+ throw new Error("Must specify either id or name.");
45
+ let crit = {}; // <any>_.pick(partial, "id", "name")
46
+ if (partial.name)
47
+ crit.name = { $eq: partial.name };
48
+ if (partial.id)
49
+ crit.ids = [partial.id];
50
+ let found = (yield this._codiacApi.AuthRole.readMany(crit, { throwNotFound: true }))[0]; // TODO: Get this from a cached secondary object
51
+ let candidate = {
52
+ enterprise: partial.enterprise,
53
+ rootMap: rootMap,
54
+ name: found.name
55
+ };
56
+ return candidate;
57
+ });
58
+ }
59
+ buildCandidate_interactively(partial, rootMap, takeDefaults) {
60
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
61
+ return yield this.buildCandidate_silently(partial, rootMap);
62
+ });
63
+ }
64
+ buildCommandString(candidate, cmd) {
65
+ cmd.push("--enterprise", candidate.enterprise);
66
+ if (candidate.id) {
67
+ cmd.push("--id", candidate.id);
68
+ }
69
+ else if (candidate.name) {
70
+ cmd.push("--name", candidate.name);
71
+ }
72
+ cmd.push("--silent");
73
+ return cmd;
74
+ }
75
+ executeTask(candidate) {
76
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
77
+ let embellisher = this.createRoleAccessEmbellisher(candidate.name);
78
+ let cabTree = this.rootMapUtils.buildCabinetTree(candidate.rootMap, embellisher);
79
+ let out = render.renderStringTree(cabTree); //, this._ui.userMessage);
80
+ this._ui.userMessage("Privileges for role: ".concat(this._styler.hilite(candidate.name)));
81
+ this._ui.userMessage(out);
82
+ return;
83
+ });
84
+ }
85
+ createRoleAccessEmbellisher(role) {
86
+ let embellisher = {
87
+ eachEnterprise: (entBranch, ent, rootMap) => {
88
+ var _a;
89
+ let rwd = this.dataAuthProvider.getRoleRwd(ent, role);
90
+ entBranch.text = "(".concat(this._styler.hilite(rwd), ") ", entBranch.text);
91
+ let childAcl = ent.defaultEnvironmentAcl ? this.dataAuthUtils.aclFromTemplate(ent.defaultEnvironmentAcl) : this.dataAuthUtils.aclFrom(ent);
92
+ let childRwd = this.dataAuthProvider.getRoleRwd(childAcl, role);
93
+ if (entBranch.children == undefined)
94
+ entBranch.children = [];
95
+ (_a = entBranch.children) === null || _a === void 0 ? void 0 : _a.unshift({ text: "(".concat(this._styler.hilite(childRwd), ") ", this._styler.dim("*new enviros*")), value: "*new enviros*" });
96
+ },
97
+ eachEnviro: (envBranch, env, ent, rootMap) => {
98
+ var _a;
99
+ let rwd = this.dataAuthProvider.getRoleRwd(env, role);
100
+ envBranch.text = "(".concat(this._styler.hilite(rwd), ") ", envBranch.text);
101
+ let childAcl = env.defaultCabinetAcl ? this.dataAuthUtils.aclFromTemplate(env.defaultCabinetAcl) : this.dataAuthUtils.aclFrom(env);
102
+ let childRwd = this.dataAuthProvider.getRoleRwd(childAcl, role);
103
+ if (envBranch.children == undefined)
104
+ envBranch.children = [];
105
+ (_a = envBranch.children) === null || _a === void 0 ? void 0 : _a.unshift({ text: "(".concat(this._styler.hilite(childRwd), ") ", this._styler.dim("*new cabinets*")), value: "*new cabinets*" });
106
+ },
107
+ eachCabinet: (cabBranch, cab, env, ent, rootMap) => {
108
+ let rwd = this.dataAuthProvider.getRoleRwd(cab, role);
109
+ cabBranch.text = "(".concat(this._styler.hilite(rwd), ") ", cabBranch.text);
110
+ },
111
+ };
112
+ return embellisher;
113
+ }
114
+ }
115
+ exports.default = AuthRoleAllowed;
116
+ AuthRoleAllowed.description = 'Renders the privileges granted to an existing Role on each enterprise, environment, and cabinet.';
117
+ AuthRoleAllowed.aliases = [];
118
+ AuthRoleAllowed.examples = [
119
+ '<%= config.bin %> <%= command.id %> -n deployer',
120
+ '<%= config.bin %> <%= command.id %> --id abc123def456',
121
+ '<%= config.bin %> <%= command.id %> -n deployer -e main'
122
+ ];
123
+ AuthRoleAllowed.flags = {
124
+ id: core_1.Flags.string({ required: false, exclusive: ["name"], description: 'System ID of the Role.' }),
125
+ enterprise: core_1.Flags.string({ char: 'e', required: false, description: '(required only if there are more than one) Name of the Enterprise in which to view the entities to which the role has access.' }),
126
+ // TODO: Move these into the base class
127
+ silent: core_1.Flags.boolean({ exclusive: ["echo", "to-script"], description: 'Non-Interactive mode; executes without any user interaction and fails on any missing or invalid arguments.' }),
128
+ echo: core_1.Flags.boolean({ exclusive: ["to-script", "silent"], description: 'Echo interaction mode; renders the equivalent non-interactive cli command for future use before final execution.' }),
129
+ "to-script": core_1.Flags.boolean({ exclusive: ["echo", "silent"], description: 'Toscript interaction mode; renders the equivalent non-interactive cli command WITHOUT any execution.' }),
130
+ "take-defaults": core_1.Flags.boolean({ exclusive: ["silent"], description: "Setting this to true prevents prompting for confirmation on parameters that were passed in or were automatically set to default values (Irrelevant in --silent mode). This behavior does NOT apply to scenarios that the command needs to override invalid user input; such cases will always prompt for confirmation. eg: when no argument was provided for file or type, and only one exists, the system will render the autoselected file unless this flag is set." })
131
+ };
132
+ AuthRoleAllowed.args = {
133
+ name: core_1.Args.string({ required: false, exclusive: ["id"], description: 'Name of the Role.' }),
134
+ };
135
+ //# sourceMappingURL=allowed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"allowed.js","sourceRoot":"","sources":["../../../../src/commands/auth/role/allowed.ts"],"names":[],"mappings":";;;AAAA,sCAAkD;AAKlD,0DAA0D;AAE1D,kEAA6D;AAE7D,sEAAoE;AAUpE,MAAqB,eAAgB,SAAQ,mCAAoC;IAAjF;;QAyBY,cAAS,GAAG,IAAI,CAAC;IAqI7B,CAAC;IAnIc,WAAW,CAAC,cAA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AAC,WAAW,EAAE,QAAQ,CAAC,EAAE,WAAW,EAAE,kHAAkH,EAAE,CAAC;IAC5L,WAAW,EAAE,YAAK,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,WAAW,EAAE,sGAAsG,EAAE,CAAC;IAClL,eAAe,EAAE,YAAK,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC,QAAQ,CAAC,EAAE,WAAW,EAAE,ycAAyc,EAAE,CAAC;CAClhB,CAAA;AAEM,oBAAI,GAAG;IACZ,IAAI,EAAE,WAAI,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,mBAAmB,EAAE,CAAC;CAC5F,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { InteractionModes } from '../../../uilogic/config-ui-utils';
2
+ import { CommandBaseExecTenant } from '../../../command-base-exec-tenant';
3
+ export type IAssignment = {
4
+ role: string;
5
+ user: string;
6
+ };
7
+ export default class AuthRoleAssign extends CommandBaseExecTenant<IAssignment> {
8
+ static description: string;
9
+ static aliases: never[];
10
+ static examples: string[];
11
+ static flags: {
12
+ role: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
13
+ user: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
14
+ silent: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
15
+ echo: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
16
+ "to-script": import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
17
+ "take-defaults": import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
18
+ };
19
+ static args: {};
20
+ protected adminOnly: boolean;
21
+ captureArgs(): Promise<[Partial<IAssignment>, InteractionModes | undefined, boolean]>;
22
+ buildCandidate_silently(partial: Partial<IAssignment>): Promise<IAssignment | undefined>;
23
+ buildCandidate_interactively(partial: Partial<IAssignment>, takeDefaults: boolean): Promise<IAssignment | undefined>;
24
+ buildCommandString(candidate: IAssignment, cmd: string[]): string[];
25
+ executeTask(candidate: IAssignment): Promise<void>;
26
+ }
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const core_1 = require("@oclif/core");
5
+ const _ = require("lodash");
6
+ const config_ui_utils_1 = require("../../../uilogic/config-ui-utils");
7
+ const command_base_exec_tenant_1 = require("../../../command-base-exec-tenant");
8
+ class AuthRoleAssign extends command_base_exec_tenant_1.CommandBaseExecTenant {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.adminOnly = true;
12
+ }
13
+ captureArgs() {
14
+ var _a, _b;
15
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
16
+ const { args, flags } = yield this.parse(AuthRoleAssign);
17
+ let partial = {};
18
+ if (flags.role)
19
+ partial.role = flags.role;
20
+ if (flags.user)
21
+ partial.user = flags.user;
22
+ // ---------------------------------------------------------------
23
+ // TODO: move everything from here down into the base class
24
+ // ---------------------------------------------------------------
25
+ const interactionMode = (this.pipedInput) ? config_ui_utils_1.InteractionModes.silent : (_b = (_a = undefined !== null && undefined !== void 0 ? undefined : (flags.echo ? config_ui_utils_1.InteractionModes.echo : undefined)) !== null && _a !== void 0 ? _a : (flags["to-script"] ? config_ui_utils_1.InteractionModes.toscript : undefined)) !== null && _b !== void 0 ? _b : (flags.silent ? config_ui_utils_1.InteractionModes.silent : undefined);
26
+ const takeDefaults = flags['take-defaults'];
27
+ return [partial, interactionMode, takeDefaults];
28
+ });
29
+ }
30
+ // /** Throws on invalid */
31
+ // private validate(partial: Partial<IAuthRoleDef>): void {
32
+ // if (partial.name == undefined || _.isEmpty(partial.name)) throw new Error("Missing name");
33
+ // let rxName = /^[a-zA-Z][a-zA-Z0-9-]{2,50}$/;
34
+ // if (!rxName.test(partial.name)) throw new Error("Invalid name: must be 3- to 50-character string of alphanumerics and hyphens, starting with a letter.");
35
+ // }
36
+ buildCandidate_silently(partial) {
37
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
38
+ if (partial.role == undefined || _.isEmpty(partial.role))
39
+ throw new Error("Must specify role.");
40
+ if (partial.user == undefined || _.isEmpty(partial.user))
41
+ throw new Error("Must specify user.");
42
+ let candidate = {
43
+ role: partial.role,
44
+ user: partial.user
45
+ };
46
+ return candidate;
47
+ });
48
+ }
49
+ buildCandidate_interactively(partial, takeDefaults) {
50
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
51
+ return yield this.buildCandidate_silently(partial);
52
+ });
53
+ }
54
+ buildCommandString(candidate, cmd) {
55
+ cmd.push("--role", candidate.role);
56
+ cmd.push("--user", candidate.user);
57
+ cmd.push("--silent");
58
+ return cmd;
59
+ }
60
+ executeTask(candidate) {
61
+ var _a, _b;
62
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
63
+ let result = yield this._codiacApi.Auth.RoleAssignment({ roleName: candidate.role, userId: candidate.user });
64
+ if (result.error)
65
+ throw _.isEmpty(result.error) ? new Error(result.message) : result.error; // TODO: this empty error BS needs to get fixed in the api or client.
66
+ if (result.success) {
67
+ this._ui.userMessage(this._styler.colorGood("Success! ").concat((_a = result.message) !== null && _a !== void 0 ? _a : "Assigned Role."));
68
+ }
69
+ else {
70
+ this._ui.userMessage((_b = result.message) !== null && _b !== void 0 ? _b : "Failed to assign role (no details given, see log for details)");
71
+ }
72
+ return;
73
+ });
74
+ }
75
+ }
76
+ exports.default = AuthRoleAssign;
77
+ AuthRoleAssign.description = 'Applies a Role to a user or group within the current tenant security context.';
78
+ AuthRoleAssign.aliases = [];
79
+ AuthRoleAssign.examples = [
80
+ '<%= config.bin %> <%= command.id %> -r deployer -u joe.cool@yourdomain.com'
81
+ ];
82
+ AuthRoleAssign.flags = {
83
+ role: core_1.Flags.string({ char: 'r', required: false, description: 'Name of the Role being assigned. Required in silent mode.' }),
84
+ user: core_1.Flags.string({ char: 'u', required: false, description: 'Username getting the role assignment. Required in silent mode.' }),
85
+ // TODO: Move these into the base class
86
+ silent: core_1.Flags.boolean({ exclusive: ["echo", "to-script"], description: 'Non-Interactive mode; executes without any user interaction and fails on any missing or invalid arguments.' }),
87
+ echo: core_1.Flags.boolean({ exclusive: ["to-script", "silent"], description: 'Echo interaction mode; renders the equivalent non-interactive cli command for future use before final execution.' }),
88
+ "to-script": core_1.Flags.boolean({ exclusive: ["echo", "silent"], description: 'Toscript interaction mode; renders the equivalent non-interactive cli command WITHOUT any execution.' }),
89
+ "take-defaults": core_1.Flags.boolean({ exclusive: ["silent"], description: "Setting this to true prevents prompting for confirmation on parameters that were passed in or were automatically set to default values (Irrelevant in --silent mode). This behavior does NOT apply to scenarios that the command needs to override invalid user input; such cases will always prompt for confirmation. eg: when no argument was provided for file or type, and only one exists, the system will render the autoselected file unless this flag is set." })
90
+ };
91
+ AuthRoleAssign.args = {};
92
+ //# sourceMappingURL=assign.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assign.js","sourceRoot":"","sources":["../../../../src/commands/auth/role/assign.ts"],"names":[],"mappings":";;;AAAA,sCAA4C;AAI5C,4BAA6B;AAK7B,sEAAoE;AAEpE,gFAA0E;AAM1E,MAAqB,cAAe,SAAQ,gDAAkC;IAA9E;;QAqBY,cAAS,GAAG,IAAI,CAAC;IAkF7B,CAAC;IAhFc,WAAW;;;YACtB,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;YAEzD,IAAI,OAAO,GAAyB,EAAE,CAAC;YAEvC,IAAI,KAAK,CAAC,IAAI;gBAAE,OAAO,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;YAC1C,IAAI,KAAK,CAAC,IAAI;gBAAE,OAAO,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;YAG1C,kEAAkE;YAClE,2DAA2D;YAC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,IAAI,EAAE,YAAK,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,EAAE,2DAA2D,EAAE,CAAC;IAC5H,IAAI,EAAE,YAAK,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,EAAE,gEAAgE,EAAE,CAAC;IAEjI,uCAAuC;IACvC,MAAM,EAAE,YAAK,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,WAAW,EAAE,4GAA4G,EAAE,CAAC;IACtL,IAAI,EAAE,YAAK,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC,WAAW,EAAE,QAAQ,CAAC,EAAE,WAAW,EAAE,kHAAkH,EAAE,CAAC;IAC5L,WAAW,EAAE,YAAK,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,WAAW,EAAE,sGAAsG,EAAE,CAAC;IAClL,eAAe,EAAE,YAAK,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC,QAAQ,CAAC,EAAE,WAAW,EAAE,ycAAyc,EAAE,CAAC;CAClhB,CAAA;AAEM,mBAAI,GAAG,EAAE,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { AuthRole } from '../../../apis/codiac-api/contracts';
2
+ import { InteractionModes } from '../../../uilogic/config-ui-utils';
3
+ import { CommandBaseExecTenant } from '../../../command-base-exec-tenant';
4
+ export type IAuthRoleDef = Pick<AuthRole, "name">;
5
+ export default class AuthRoleCreate extends CommandBaseExecTenant<IAuthRoleDef> {
6
+ static description: string;
7
+ static aliases: never[];
8
+ static examples: string[];
9
+ static flags: {
10
+ silent: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
11
+ echo: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
12
+ "to-script": import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
13
+ "take-defaults": import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
14
+ };
15
+ static args: {
16
+ name: import("@oclif/core/lib/interfaces/parser").Arg<string | undefined, Record<string, unknown>>;
17
+ };
18
+ protected adminOnly: boolean;
19
+ captureArgs(): Promise<[Partial<IAuthRoleDef>, InteractionModes | undefined, boolean]>;
20
+ buildCandidate_silently(partial: Partial<IAuthRoleDef>): Promise<IAuthRoleDef | undefined>;
21
+ buildCandidate_interactively(partial: Partial<IAuthRoleDef>, takeDefaults: boolean): Promise<IAuthRoleDef | undefined>;
22
+ buildCommandString(candidate: AuthRole, cmd: string[]): string[];
23
+ executeTask(candidate: AuthRole): Promise<void>;
24
+ }
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const core_1 = require("@oclif/core");
5
+ const _ = require("lodash");
6
+ const config_ui_utils_1 = require("../../../uilogic/config-ui-utils");
7
+ const command_base_exec_tenant_1 = require("../../../command-base-exec-tenant");
8
+ class AuthRoleCreate extends command_base_exec_tenant_1.CommandBaseExecTenant {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.adminOnly = true;
12
+ }
13
+ captureArgs() {
14
+ var _a, _b;
15
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
16
+ const { args, flags } = yield this.parse(AuthRoleCreate);
17
+ let partial = {};
18
+ if (args.name)
19
+ partial.name = args.name;
20
+ // ---------------------------------------------------------------
21
+ // TODO: move everything from here down into the base class
22
+ // ---------------------------------------------------------------
23
+ const interactionMode = (this.pipedInput) ? config_ui_utils_1.InteractionModes.silent : (_b = (_a = undefined !== null && undefined !== void 0 ? undefined : (flags.echo ? config_ui_utils_1.InteractionModes.echo : undefined)) !== null && _a !== void 0 ? _a : (flags["to-script"] ? config_ui_utils_1.InteractionModes.toscript : undefined)) !== null && _b !== void 0 ? _b : (flags.silent ? config_ui_utils_1.InteractionModes.silent : undefined);
24
+ const takeDefaults = flags['take-defaults'];
25
+ return [partial, interactionMode, takeDefaults];
26
+ });
27
+ }
28
+ // /** Throws on invalid */
29
+ // private validate(partial: Partial<IAuthRoleDef>): void {
30
+ // if (partial.name == undefined || _.isEmpty(partial.name)) throw new Error("Missing name");
31
+ // let rxName = /^[a-zA-Z][a-zA-Z0-9-]{2,50}$/;
32
+ // if (!rxName.test(partial.name)) throw new Error("Invalid name: must be 3- to 50-character string of alphanumerics and hyphens, starting with a letter.");
33
+ // }
34
+ buildCandidate_silently(partial) {
35
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
36
+ // this.validate(partial);
37
+ if (partial.name == undefined || _.isEmpty(partial.name))
38
+ throw new Error("Missing name");
39
+ let rxName = /^[a-zA-Z][a-zA-Z0-9-]{2,50}$/;
40
+ if (!rxName.test(partial.name))
41
+ throw new Error("Invalid name: must be 3- to 50-character string of alphanumerics and hyphens, starting with a letter.");
42
+ let candidate = {
43
+ name: partial.name
44
+ };
45
+ return candidate;
46
+ });
47
+ }
48
+ buildCandidate_interactively(partial, takeDefaults) {
49
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
50
+ return yield this.buildCandidate_silently(partial);
51
+ });
52
+ }
53
+ buildCommandString(candidate, cmd) {
54
+ cmd.push("--name", candidate.name);
55
+ cmd.push("--silent");
56
+ return cmd;
57
+ }
58
+ executeTask(candidate) {
59
+ var _a, _b;
60
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
61
+ let result = yield this._codiacApi.AuthRole.tryCreate({ name: candidate.name, descriptor: candidate.name });
62
+ if (result.error)
63
+ throw result.error;
64
+ if (result.success) {
65
+ this._ui.userMessage(this._styler.colorGood("Success! ").concat((_a = result.message) !== null && _a !== void 0 ? _a : "Created new Role."));
66
+ }
67
+ else {
68
+ this._ui.userMessage((_b = result.message) !== null && _b !== void 0 ? _b : "Operation failed without error (Check log for details).");
69
+ }
70
+ return;
71
+ });
72
+ }
73
+ }
74
+ exports.default = AuthRoleCreate;
75
+ AuthRoleCreate.description = 'Adds a new Role to the current tenant security context. It is the Role object to which various types of access are granted, and a user or group is given rights by assigning them one or more roles.';
76
+ AuthRoleCreate.aliases = [];
77
+ AuthRoleCreate.examples = [
78
+ '<%= config.bin %> <%= command.id %> -n deployer',
79
+ ];
80
+ AuthRoleCreate.flags = {
81
+ // TODO: Move these into the base class
82
+ silent: core_1.Flags.boolean({ exclusive: ["echo", "to-script"], description: 'Non-Interactive mode; executes without any user interaction and fails on any missing or invalid arguments.' }),
83
+ echo: core_1.Flags.boolean({ exclusive: ["to-script", "silent"], description: 'Echo interaction mode; renders the equivalent non-interactive cli command for future use before final execution.' }),
84
+ "to-script": core_1.Flags.boolean({ exclusive: ["echo", "silent"], description: 'Toscript interaction mode; renders the equivalent non-interactive cli command WITHOUT any execution.' }),
85
+ "take-defaults": core_1.Flags.boolean({ exclusive: ["silent"], description: "Setting this to true prevents prompting for confirmation on parameters that were passed in or were automatically set to default values (Irrelevant in --silent mode). This behavior does NOT apply to scenarios that the command needs to override invalid user input; such cases will always prompt for confirmation. eg: when no argument was provided for file or type, and only one exists, the system will render the autoselected file unless this flag is set." })
86
+ };
87
+ AuthRoleCreate.args = {
88
+ name: core_1.Args.string({ required: false, description: 'Name to give the new role.' }),
89
+ };
90
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../../../../src/commands/auth/role/create.ts"],"names":[],"mappings":";;;AAAA,sCAAkD;AAIlD,4BAA6B;AAK7B,sEAAoE;AAEpE,gFAA0E;AAM1E,MAAqB,cAAe,SAAQ,gDAAmC;IAA/E;;QAqBY,cAAS,GAAG,IAAI,CAAC;IAiF7B,CAAC;IA/Ec,WAAW;;;YACtB,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;YAEzD,IAAI,OAAO,GAA0B,EAAE,CAAC;YAExC,IAAI,IAAI,CAAC,IAAI;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