@bctrl/cli 0.1.4 → 0.1.5

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.
@@ -1,36 +1,34 @@
1
1
  import { Command } from 'commander';
2
- import { createDeleteCommand, createJsonBodyCommand, createListCommand, createViewCommand, } from '../shared/rest.js';
2
+ import { createOperationDeleteCommand, createOperationJsonBodyCommand, createOperationListCommand, createOperationViewCommand, } from '../shared/operation.js';
3
3
  export function createToolsetCommand(factory) {
4
4
  const command = new Command('toolset').description('Manage BCTRL toolsets');
5
- command.addCommand(createListCommand(factory, {
5
+ command.addCommand(createOperationListCommand(factory, {
6
+ operationId: 'toolsets.list',
6
7
  description: 'List toolsets',
7
- path: '/toolsets',
8
8
  configure: (cmd) => cmd.option('--space <id>', 'Filter by space id'),
9
9
  query: (options) => ({
10
10
  spaceId: typeof options.space === 'string' ? options.space : undefined,
11
11
  }),
12
12
  }));
13
- command.addCommand(createViewCommand(factory, {
13
+ command.addCommand(createOperationViewCommand(factory, {
14
+ operationId: 'toolsets.get',
14
15
  name: 'get',
15
16
  description: 'View a toolset',
16
- path: '/toolsets/{id}',
17
17
  }));
18
- command.addCommand(createJsonBodyCommand(factory, {
18
+ command.addCommand(createOperationJsonBodyCommand(factory, {
19
+ operationId: 'toolsets.create',
19
20
  name: 'create',
20
21
  description: 'Create a toolset',
21
- method: 'post',
22
- path: '/toolsets',
23
22
  }));
24
- command.addCommand(createJsonBodyCommand(factory, {
23
+ command.addCommand(createOperationJsonBodyCommand(factory, {
24
+ operationId: 'toolsets.update',
25
25
  name: 'patch',
26
26
  description: 'Edit a toolset',
27
- method: 'patch',
28
- path: '/toolsets/{id}',
29
27
  argNames: ['id'],
30
28
  }));
31
- command.addCommand(createDeleteCommand(factory, {
29
+ command.addCommand(createOperationDeleteCommand(factory, {
30
+ operationId: 'toolsets.delete',
32
31
  description: 'Delete a toolset',
33
- path: '/toolsets/{id}',
34
32
  }));
35
33
  return command;
36
34
  }
@@ -1,13 +1,13 @@
1
1
  import { Command } from 'commander';
2
2
  import { addOutputFlags } from '../shared/output.js';
3
- import { requestAndPrint } from '../shared/rest.js';
3
+ import { outputFlags, requestOperationAndPrint } from '../shared/operation.js';
4
4
  export function createUsageCommand(factory) {
5
5
  const command = addOutputFlags(new Command('usage').description('Get organization usage'));
6
6
  command.action(async (options) => {
7
- await requestAndPrint(factory, 'get', '/usage', { output: options });
7
+ await requestOperationAndPrint(factory, 'usage.get', { output: outputFlags(options) });
8
8
  });
9
9
  command.addCommand(addOutputFlags(new Command('get').description('Get organization usage')).action(async (options) => {
10
- await requestAndPrint(factory, 'get', '/usage', { output: options });
10
+ await requestOperationAndPrint(factory, 'usage.get', { output: outputFlags(options) });
11
11
  }));
12
12
  return command;
13
13
  }
@@ -3,12 +3,12 @@ import { CliError } from '../../runtime/errors.js';
3
3
  import { readJsonFile, readText } from '../shared/io.js';
4
4
  import { parsePositiveInteger } from '../shared/options.js';
5
5
  import { addOutputFlags } from '../shared/output.js';
6
- import { createDeleteCommand, createJsonBodyCommand, createListCommand, createViewCommand, pathTemplate, requestAndPrint, } from '../shared/rest.js';
6
+ import { createOperationDeleteCommand, createOperationJsonBodyCommand, createOperationListCommand, createOperationViewCommand, outputFlags, requestOperationAndPrint, } from '../shared/operation.js';
7
7
  export function createVaultCommand(factory) {
8
8
  const command = new Command('vault').description('Manage vault secrets and TOTP codes');
9
- command.addCommand(createListCommand(factory, {
9
+ command.addCommand(createOperationListCommand(factory, {
10
+ operationId: 'vault.secrets.list',
10
11
  description: 'List vault secret metadata',
11
- path: '/vault/secrets',
12
12
  configure: (cmd) => cmd
13
13
  .option('--prefix <prefix>', 'Filter by secret key prefix')
14
14
  .option('--origin <origin>', 'Filter by origin')
@@ -21,18 +21,18 @@ export function createVaultCommand(factory) {
21
21
  limit: typeof options.limit === 'number' ? options.limit : undefined,
22
22
  }),
23
23
  }));
24
- command.addCommand(createViewCommand(factory, {
24
+ command.addCommand(createOperationViewCommand(factory, {
25
+ operationId: 'vault.secrets.get',
25
26
  name: 'get',
26
27
  description: 'View vault secret metadata',
27
- path: '/vault/secrets/{key}',
28
28
  argName: 'key',
29
29
  }));
30
30
  command.addCommand(createVaultReadCommand(factory));
31
31
  command.addCommand(createVaultSetCommand(factory));
32
32
  command.addCommand(createVaultPatchCommand(factory));
33
- command.addCommand(createDeleteCommand(factory, {
33
+ command.addCommand(createOperationDeleteCommand(factory, {
34
+ operationId: 'vault.secrets.delete',
34
35
  description: 'Delete a vault secret',
35
- path: '/vault/secrets/{key}',
36
36
  argNames: ['key'],
37
37
  }));
38
38
  command.addCommand(createVaultTotpCommand(factory));
@@ -46,17 +46,17 @@ function createVaultReadCommand(factory) {
46
46
  if (factory.io.isStdoutTTY() && options.reveal !== true) {
47
47
  throw new CliError('Refusing to print a secret to a terminal without --reveal');
48
48
  }
49
- await requestAndPrint(factory, 'get', `/vault/secrets/${encodeURIComponent(key)}/value`, {
50
- output: options,
49
+ await requestOperationAndPrint(factory, 'vault.secrets.value', {
50
+ pathParams: { key },
51
+ output: outputFlags(options),
51
52
  });
52
53
  });
53
54
  }
54
55
  function createVaultSetCommand(factory) {
55
- return createJsonBodyCommand(factory, {
56
+ return createOperationJsonBodyCommand(factory, {
57
+ operationId: 'vault.secrets.upsert',
56
58
  name: 'set',
57
59
  description: 'Create or replace a vault secret',
58
- method: 'put',
59
- path: '/vault/secrets/{key}',
60
60
  argNames: ['key'],
61
61
  configure: (cmd) => cmd
62
62
  .option('--type <type>', 'Secret type: login or value')
@@ -71,8 +71,9 @@ function createVaultSetCommand(factory) {
71
71
  .option('--origin-pattern <pattern...>', 'Allowed origin pattern')
72
72
  .option('--input <path>', 'Read full JSON request body from file, or - for stdin'),
73
73
  body: async (args, options) => {
74
- if (typeof options.input === 'string')
75
- return readJsonFile(options.input);
74
+ if (typeof options.input === 'string') {
75
+ return (await readJsonFile(options.input));
76
+ }
76
77
  const password = typeof options.passwordFromFile === 'string'
77
78
  ? (await readText(options.passwordFromFile)).trimEnd()
78
79
  : options.password;
@@ -118,11 +119,10 @@ function createVaultSetCommand(factory) {
118
119
  });
119
120
  }
120
121
  function createVaultPatchCommand(factory) {
121
- return createJsonBodyCommand(factory, {
122
+ return createOperationJsonBodyCommand(factory, {
123
+ operationId: 'vault.secrets.update',
122
124
  name: 'patch',
123
125
  description: 'Update a vault secret',
124
- method: 'patch',
125
- path: '/vault/secrets/{key}',
126
126
  argNames: ['key'],
127
127
  configure: (cmd) => cmd
128
128
  .option('--value <value>', 'Generic secret value')
@@ -140,8 +140,9 @@ function createVaultPatchCommand(factory) {
140
140
  .option('--clear-origin-patterns', 'Remove origin patterns')
141
141
  .option('--input <path>', 'Read full JSON request body from file, or - for stdin'),
142
142
  body: async (_args, options) => {
143
- if (typeof options.input === 'string')
144
- return readJsonFile(options.input);
143
+ if (typeof options.input === 'string') {
144
+ return (await readJsonFile(options.input));
145
+ }
145
146
  const password = typeof options.passwordFromFile === 'string'
146
147
  ? (await readText(options.passwordFromFile)).trimEnd()
147
148
  : options.password;
@@ -168,8 +169,9 @@ function createVaultTotpCommand(factory) {
168
169
  return addOutputFlags(new Command('totp')
169
170
  .description('Generate the current TOTP code for a vault secret')
170
171
  .argument('<key>')).action(async (key, options) => {
171
- await requestAndPrint(factory, 'get', pathTemplate('/vault/secrets/{key}/totp', { key }), {
172
- output: options,
172
+ await requestOperationAndPrint(factory, 'vault.secrets.totp', {
173
+ pathParams: { key },
174
+ output: outputFlags(options),
173
175
  });
174
176
  });
175
177
  }