clever-tools 4.7.1 → 4.8.0

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 (69) hide show
  1. package/bin/clever.js +11 -1
  2. package/package.json +2 -2
  3. package/src/clever-client/drains.js +18 -18
  4. package/src/commands/README.md +1 -0
  5. package/src/commands/accesslogs/accesslogs.command.js +2 -2
  6. package/src/commands/activity/activity.command.js +1 -1
  7. package/src/commands/addon/addon.create.command.js +2 -3
  8. package/src/commands/addon/addon.delete.command.js +2 -2
  9. package/src/commands/addon/addon.docs.md +2 -2
  10. package/src/commands/addon/addon.env.command.js +4 -6
  11. package/src/commands/config-provider/config-provider.command.js +0 -4
  12. package/src/commands/config-provider/config-provider.import.command.js +1 -1
  13. package/src/commands/config-provider/config-provider.list.command.js +8 -19
  14. package/src/commands/config-provider/config-provider.open.command.js +1 -1
  15. package/src/commands/console/console.command.js +3 -2
  16. package/src/commands/curl/curl.command.js +0 -1
  17. package/src/commands/database/database.backups.command.js +4 -7
  18. package/src/commands/database/database.backups.download.command.js +5 -7
  19. package/src/commands/database/database.command.js +0 -4
  20. package/src/commands/database/database.docs.md +2 -2
  21. package/src/commands/deploy/deploy.command.js +1 -1
  22. package/src/commands/deploy/deploy.docs.md +1 -1
  23. package/src/commands/drain/drain.command.js +14 -9
  24. package/src/commands/drain/drain.create.command.js +9 -13
  25. package/src/commands/drain/drain.disable.command.js +7 -7
  26. package/src/commands/drain/drain.docs.md +6 -0
  27. package/src/commands/drain/drain.enable.command.js +7 -7
  28. package/src/commands/drain/drain.get.command.js +12 -8
  29. package/src/commands/drain/drain.remove.command.js +7 -7
  30. package/src/commands/emails/emails.open.command.js +1 -4
  31. package/src/commands/global.commands.js +18 -0
  32. package/src/commands/global.options.js +7 -7
  33. package/src/commands/help/help.command.js +0 -3
  34. package/src/commands/k8s/k8s.command.js +0 -4
  35. package/src/commands/k8s/k8s.delete.command.js +2 -2
  36. package/src/commands/k8s/k8s.docs.md +1 -1
  37. package/src/commands/logs/logs.command.js +4 -5
  38. package/src/commands/ng/ng.docs.md +0 -1
  39. package/src/commands/ng/ng.get-config.command.js +3 -14
  40. package/src/commands/ng/ng.options.js +1 -1
  41. package/src/commands/notify-email/notify-email.remove.command.js +2 -2
  42. package/src/commands/oauth-consumers/oauth-consumers.args.js +8 -0
  43. package/src/commands/oauth-consumers/oauth-consumers.command.js +6 -0
  44. package/src/commands/oauth-consumers/oauth-consumers.create.command.js +64 -0
  45. package/src/commands/oauth-consumers/oauth-consumers.delete.command.js +33 -0
  46. package/src/commands/oauth-consumers/oauth-consumers.docs.md +130 -0
  47. package/src/commands/oauth-consumers/oauth-consumers.get.command.js +67 -0
  48. package/src/commands/oauth-consumers/oauth-consumers.list.command.js +34 -0
  49. package/src/commands/oauth-consumers/oauth-consumers.open.command.js +18 -0
  50. package/src/commands/oauth-consumers/oauth-consumers.options.js +48 -0
  51. package/src/commands/oauth-consumers/oauth-consumers.update.command.js +83 -0
  52. package/src/commands/open/open.command.js +1 -1
  53. package/src/commands/profile/profile.open.command.js +1 -1
  54. package/src/commands/restart/restart.docs.md +1 -1
  55. package/src/commands/ssh-keys/ssh-keys.open.command.js +1 -1
  56. package/src/commands/webhooks/webhooks.remove.command.js +2 -2
  57. package/src/lib/cliparse-patched.js +2 -0
  58. package/src/lib/get-command-info.js +3 -1
  59. package/src/lib/get-command-info.types.d.ts +4 -0
  60. package/src/lib/operator-commands.js +11 -25
  61. package/src/lib/print-items-by-owner.js +38 -0
  62. package/src/lib/prompts.js +23 -1
  63. package/src/lib/zod-utils.js +51 -0
  64. package/src/models/drain.js +17 -0
  65. package/src/models/ids-resolver.js +38 -20
  66. package/src/models/ng.js +2 -2
  67. package/src/models/notification.js +0 -4
  68. package/src/models/oauth-consumer.js +77 -0
  69. package/src/models/utils.js +1 -1
@@ -2,9 +2,9 @@ import { disableDrain } from '../../clever-client/drains.js';
2
2
  import { defineCommand } from '../../lib/define-command.js';
3
3
  import { styleText } from '../../lib/style-text.js';
4
4
  import { Logger } from '../../logger.js';
5
- import * as Application from '../../models/application.js';
5
+ import { resolveDrainResource } from '../../models/drain.js';
6
6
  import { sendToApi } from '../../models/send-to-api.js';
7
- import { aliasOption, appIdOrNameOption } from '../global.options.js';
7
+ import { addonIdOrRealIdOption, aliasOption, appIdOrNameOption } from '../global.options.js';
8
8
  import { drainIdArg } from './drain.args.js';
9
9
 
10
10
  export const drainDisableCommand = defineCommand({
@@ -12,15 +12,15 @@ export const drainDisableCommand = defineCommand({
12
12
  since: '0.9.0',
13
13
  options: {
14
14
  alias: aliasOption,
15
- app: appIdOrNameOption,
15
+ appIdOrName: appIdOrNameOption,
16
+ addonIdOrRealId: addonIdOrRealIdOption,
16
17
  },
17
18
  args: [drainIdArg],
18
19
  async handler(options, drainId) {
19
- const { alias, app: appIdOrName } = options;
20
+ const { alias, appIdOrName, addonIdOrRealId } = options;
21
+ const { ownerId, resourceId } = await resolveDrainResource(alias, appIdOrName, addonIdOrRealId);
20
22
 
21
- const { ownerId, appId: applicationId } = await Application.resolveId(appIdOrName, alias);
22
-
23
- await disableDrain({ ownerId, applicationId, drainId }).then(sendToApi);
23
+ await disableDrain({ ownerId, resourceId, drainId }).then(sendToApi);
24
24
 
25
25
  Logger.printSuccess(`Drain ${styleText(['bold', 'green'], drainId)} has been successfully disabled!`);
26
26
  },
@@ -12,6 +12,7 @@ clever drain [options]
12
12
 
13
13
  |Name|Description|
14
14
  |---|---|
15
+ |`--addon` `<addon-id>`|Add-on ID or real ID|
15
16
  |`-a`, `--alias` `<alias>`|Short name for the application|
16
17
  |`--app` `<app-id\|app-name>`|Application to manage by its ID (or name, if unambiguous)|
17
18
  |`-F`, `--format` `<format>`|Output format (human, json) (default: human)|
@@ -35,6 +36,7 @@ clever drain create <drain-type> <drain-url> [options]
35
36
 
36
37
  |Name|Description|
37
38
  |---|---|
39
+ |`--addon` `<addon-id>`|Add-on ID or real ID|
38
40
  |`-a`, `--alias` `<alias>`|Short name for the application|
39
41
  |`-k`, `--api-key` `<api-key>`|API key (for newrelic)|
40
42
  |`--app` `<app-id\|app-name>`|Application to manage by its ID (or name, if unambiguous)|
@@ -61,6 +63,7 @@ clever drain disable <drain-id> [options]
61
63
 
62
64
  |Name|Description|
63
65
  |---|---|
66
+ |`--addon` `<addon-id>`|Add-on ID or real ID|
64
67
  |`-a`, `--alias` `<alias>`|Short name for the application|
65
68
  |`--app` `<app-id\|app-name>`|Application to manage by its ID (or name, if unambiguous)|
66
69
 
@@ -82,6 +85,7 @@ clever drain enable <drain-id> [options]
82
85
 
83
86
  |Name|Description|
84
87
  |---|---|
88
+ |`--addon` `<addon-id>`|Add-on ID or real ID|
85
89
  |`-a`, `--alias` `<alias>`|Short name for the application|
86
90
  |`--app` `<app-id\|app-name>`|Application to manage by its ID (or name, if unambiguous)|
87
91
 
@@ -103,6 +107,7 @@ clever drain get <drain-id> [options]
103
107
 
104
108
  |Name|Description|
105
109
  |---|---|
110
+ |`--addon` `<addon-id>`|Add-on ID or real ID|
106
111
  |`-a`, `--alias` `<alias>`|Short name for the application|
107
112
  |`--app` `<app-id\|app-name>`|Application to manage by its ID (or name, if unambiguous)|
108
113
  |`-F`, `--format` `<format>`|Output format (human, json) (default: human)|
@@ -125,5 +130,6 @@ clever drain remove <drain-id> [options]
125
130
 
126
131
  |Name|Description|
127
132
  |---|---|
133
+ |`--addon` `<addon-id>`|Add-on ID or real ID|
128
134
  |`-a`, `--alias` `<alias>`|Short name for the application|
129
135
  |`--app` `<app-id\|app-name>`|Application to manage by its ID (or name, if unambiguous)|
@@ -2,9 +2,9 @@ import { enableDrain } from '../../clever-client/drains.js';
2
2
  import { defineCommand } from '../../lib/define-command.js';
3
3
  import { styleText } from '../../lib/style-text.js';
4
4
  import { Logger } from '../../logger.js';
5
- import * as Application from '../../models/application.js';
5
+ import { resolveDrainResource } from '../../models/drain.js';
6
6
  import { sendToApi } from '../../models/send-to-api.js';
7
- import { aliasOption, appIdOrNameOption } from '../global.options.js';
7
+ import { addonIdOrRealIdOption, aliasOption, appIdOrNameOption } from '../global.options.js';
8
8
  import { drainIdArg } from './drain.args.js';
9
9
 
10
10
  export const drainEnableCommand = defineCommand({
@@ -12,15 +12,15 @@ export const drainEnableCommand = defineCommand({
12
12
  since: '0.9.0',
13
13
  options: {
14
14
  alias: aliasOption,
15
- app: appIdOrNameOption,
15
+ appIdOrName: appIdOrNameOption,
16
+ addonIdOrRealId: addonIdOrRealIdOption,
16
17
  },
17
18
  args: [drainIdArg],
18
19
  async handler(options, drainId) {
19
- const { alias, app: appIdOrName } = options;
20
+ const { alias, appIdOrName, addonIdOrRealId } = options;
21
+ const { ownerId, resourceId } = await resolveDrainResource(alias, appIdOrName, addonIdOrRealId);
20
22
 
21
- const { ownerId, appId: applicationId } = await Application.resolveId(appIdOrName, alias);
22
-
23
- await enableDrain({ ownerId, applicationId, drainId }).then(sendToApi);
23
+ await enableDrain({ ownerId, resourceId, drainId }).then(sendToApi);
24
24
 
25
25
  Logger.printSuccess(`Drain ${styleText(['bold', 'green'], drainId)} has been successfully enabled!`);
26
26
  },
@@ -1,10 +1,14 @@
1
1
  import { getDrain } from '../../clever-client/drains.js';
2
2
  import { defineCommand } from '../../lib/define-command.js';
3
3
  import { Logger } from '../../logger.js';
4
- import * as Application from '../../models/application.js';
5
- import { formatDrain } from '../../models/drain.js';
4
+ import { formatDrain, resolveDrainResource } from '../../models/drain.js';
6
5
  import { sendToApi } from '../../models/send-to-api.js';
7
- import { aliasOption, appIdOrNameOption, humanJsonOutputFormatOption } from '../global.options.js';
6
+ import {
7
+ addonIdOrRealIdOption,
8
+ aliasOption,
9
+ appIdOrNameOption,
10
+ humanJsonOutputFormatOption,
11
+ } from '../global.options.js';
8
12
  import { drainIdArg } from './drain.args.js';
9
13
 
10
14
  export const drainGetCommand = defineCommand({
@@ -12,16 +16,16 @@ export const drainGetCommand = defineCommand({
12
16
  since: '0.9.0',
13
17
  options: {
14
18
  alias: aliasOption,
15
- app: appIdOrNameOption,
19
+ appIdOrName: appIdOrNameOption,
20
+ addonIdOrRealId: addonIdOrRealIdOption,
16
21
  format: humanJsonOutputFormatOption,
17
22
  },
18
23
  args: [drainIdArg],
19
24
  async handler(options, drainId) {
20
- const { alias, app: appIdOrName, format } = options;
25
+ const { alias, appIdOrName, addonIdOrRealId, format } = options;
26
+ const { ownerId, resourceId } = await resolveDrainResource(alias, appIdOrName, addonIdOrRealId);
21
27
 
22
- const { ownerId, appId: applicationId } = await Application.resolveId(appIdOrName, alias);
23
-
24
- const drain = await getDrain({ ownerId, applicationId, drainId }).then(sendToApi);
28
+ const drain = await getDrain({ ownerId, resourceId, drainId }).then(sendToApi);
25
29
 
26
30
  switch (format) {
27
31
  case 'json': {
@@ -2,9 +2,9 @@ import { deleteDrain } from '../../clever-client/drains.js';
2
2
  import { defineCommand } from '../../lib/define-command.js';
3
3
  import { styleText } from '../../lib/style-text.js';
4
4
  import { Logger } from '../../logger.js';
5
- import * as Application from '../../models/application.js';
5
+ import { resolveDrainResource } from '../../models/drain.js';
6
6
  import { sendToApi } from '../../models/send-to-api.js';
7
- import { aliasOption, appIdOrNameOption } from '../global.options.js';
7
+ import { addonIdOrRealIdOption, aliasOption, appIdOrNameOption } from '../global.options.js';
8
8
  import { drainIdArg } from './drain.args.js';
9
9
 
10
10
  export const drainRemoveCommand = defineCommand({
@@ -12,15 +12,15 @@ export const drainRemoveCommand = defineCommand({
12
12
  since: '0.9.0',
13
13
  options: {
14
14
  alias: aliasOption,
15
- app: appIdOrNameOption,
15
+ appIdOrName: appIdOrNameOption,
16
+ addonIdOrRealId: addonIdOrRealIdOption,
16
17
  },
17
18
  args: [drainIdArg],
18
19
  async handler(options, drainId) {
19
- const { alias, app: appIdOrName } = options;
20
+ const { alias, appIdOrName, addonIdOrRealId } = options;
21
+ const { ownerId, resourceId } = await resolveDrainResource(alias, appIdOrName, addonIdOrRealId);
20
22
 
21
- const { ownerId, appId: applicationId } = await Application.resolveId(appIdOrName, alias);
22
-
23
- await deleteDrain({ ownerId, applicationId, drainId }).then(sendToApi);
23
+ await deleteDrain({ ownerId, resourceId, drainId }).then(sendToApi);
24
24
  Logger.printSuccess(`Drain ${styleText(['bold', 'green'], drainId)} has been successfully removed!`);
25
25
  },
26
26
  });
@@ -7,9 +7,6 @@ export const emailsOpenCommand = defineCommand({
7
7
  options: {},
8
8
  args: [],
9
9
  handler() {
10
- return openBrowser(
11
- '/users/me/emails',
12
- 'Opening the email addresses management page of the Console in your browser',
13
- );
10
+ return openBrowser('/users/me/emails', 'Opening the emails page in the browser…');
14
11
  },
15
12
  });
@@ -117,6 +117,13 @@ import { ngUnlinkCommand } from './ng/ng.unlink.command.js';
117
117
  import { notifyEmailAddCommand } from './notify-email/notify-email.add.command.js';
118
118
  import { notifyEmailCommand } from './notify-email/notify-email.command.js';
119
119
  import { notifyEmailRemoveCommand } from './notify-email/notify-email.remove.command.js';
120
+ import { oauthConsumersCommand } from './oauth-consumers/oauth-consumers.command.js';
121
+ import { oauthConsumersCreateCommand } from './oauth-consumers/oauth-consumers.create.command.js';
122
+ import { oauthConsumersDeleteCommand } from './oauth-consumers/oauth-consumers.delete.command.js';
123
+ import { oauthConsumersGetCommand } from './oauth-consumers/oauth-consumers.get.command.js';
124
+ import { oauthConsumersListCommand } from './oauth-consumers/oauth-consumers.list.command.js';
125
+ import { oauthConsumersOpenCommand } from './oauth-consumers/oauth-consumers.open.command.js';
126
+ import { oauthConsumersUpdateCommand } from './oauth-consumers/oauth-consumers.update.command.js';
120
127
  import { openCommand } from './open/open.command.js';
121
128
  import { otoroshiCommand } from './otoroshi/otoroshi.command.js';
122
129
  import { otoroshiDisableNgCommand } from './otoroshi/otoroshi.disable-ng.command.js';
@@ -384,6 +391,17 @@ export const globalCommands = {
384
391
  unlink: ngUnlinkCommand,
385
392
  },
386
393
  ],
394
+ 'oauth-consumers': [
395
+ oauthConsumersCommand,
396
+ {
397
+ create: oauthConsumersCreateCommand,
398
+ delete: oauthConsumersDeleteCommand,
399
+ get: oauthConsumersGetCommand,
400
+ list: oauthConsumersListCommand,
401
+ open: oauthConsumersOpenCommand,
402
+ update: oauthConsumersUpdateCommand,
403
+ },
404
+ ],
387
405
  'notify-email': [
388
406
  notifyEmailCommand,
389
407
  {
@@ -23,7 +23,7 @@ export const appIdOrNameOption = defineOption({
23
23
  export const logsFormatOption = defineOption({
24
24
  name: 'format',
25
25
  schema: z.enum(['human', 'json', 'json-stream']).default('human'),
26
- description: 'Output format (human, json, json-stream)',
26
+ description: 'Output format',
27
27
  aliases: ['F'],
28
28
  placeholder: 'format',
29
29
  });
@@ -44,7 +44,7 @@ export const afterOption = defineOption({
44
44
  placeholder: 'after',
45
45
  });
46
46
 
47
- export const addonIdOption = defineOption({
47
+ export const addonIdOrRealIdOption = defineOption({
48
48
  name: 'addon',
49
49
  schema: z.string().optional(),
50
50
  description: 'Add-on ID or real ID',
@@ -62,22 +62,22 @@ export const orgaIdOrNameOption = defineOption({
62
62
  export const humanJsonOutputFormatOption = defineOption({
63
63
  name: 'format',
64
64
  schema: z.enum(['human', 'json']).default('human'),
65
- description: 'Output format (human, json)',
65
+ description: 'Output format',
66
66
  aliases: ['F'],
67
67
  placeholder: 'format',
68
68
  });
69
69
 
70
- export const confirmAddonDeletionOption = defineOption({
70
+ export const skipConfirmationOption = defineOption({
71
71
  name: 'yes',
72
72
  schema: z.boolean().default(false),
73
- description: 'Skip confirmation and delete the add-on directly',
73
+ description: 'Skip confirmation and proceed with deletion directly',
74
74
  aliases: ['y'],
75
75
  });
76
76
 
77
77
  export const envFormatOption = defineOption({
78
78
  name: 'format',
79
79
  schema: z.enum(['human', 'json', 'shell']).default('human'),
80
- description: 'Output format (human, json, shell)',
80
+ description: 'Output format',
81
81
  aliases: ['F'],
82
82
  placeholder: 'format',
83
83
  });
@@ -107,7 +107,7 @@ export const followDeployLogsOption = defineOption({
107
107
  export const exitOnDeployOption = defineOption({
108
108
  name: 'exit-on',
109
109
  schema: z.enum(['deploy-start', 'deploy-end', 'never']).default('deploy-end'),
110
- description: 'Step at which the logs streaming is ended, steps are: deploy-start, deploy-end, never',
110
+ description: 'Step at which the logs streaming is ended',
111
111
  aliases: ['e'],
112
112
  placeholder: 'step',
113
113
  });
@@ -3,7 +3,4 @@ import { defineCommand } from '../../lib/define-command.js';
3
3
  export const helpCommand = defineCommand({
4
4
  description: 'Display help about the Clever Cloud CLI',
5
5
  since: '0.1.0',
6
- options: {},
7
- args: [],
8
- handler: null,
9
6
  });
@@ -5,8 +5,4 @@ export const k8sCommand = defineCommand({
5
5
  since: '4.3.0',
6
6
  isExperimental: true,
7
7
  featureFlag: 'k8s',
8
- options: {},
9
- args: [],
10
- // Parent command - no handler, only contains subcommands
11
- handler: null,
12
8
  });
@@ -3,7 +3,7 @@ import { k8sDelete } from '../../lib/k8s.js';
3
3
  import { confirm } from '../../lib/prompts.js';
4
4
  import { styleText } from '../../lib/style-text.js';
5
5
  import { Logger } from '../../logger.js';
6
- import { confirmAddonDeletionOption, orgaIdOrNameOption } from '../global.options.js';
6
+ import { orgaIdOrNameOption, skipConfirmationOption } from '../global.options.js';
7
7
  import { k8sIdOrNameArg } from './k8s.args.js';
8
8
 
9
9
  export const k8sDeleteCommand = defineCommand({
@@ -11,7 +11,7 @@ export const k8sDeleteCommand = defineCommand({
11
11
  since: '4.3.0',
12
12
  options: {
13
13
  org: orgaIdOrNameOption,
14
- yes: confirmAddonDeletionOption,
14
+ yes: skipConfirmationOption,
15
15
  },
16
16
  args: [k8sIdOrNameArg],
17
17
  async handler(options, clusterIdOrName) {
@@ -72,7 +72,7 @@ clever k8s delete <cluster-id|cluster-name> [options]
72
72
  |Name|Description|
73
73
  |---|---|
74
74
  |`-o`, `--org`, `--owner` `<org-id\|org-name>`|Organisation to target by its ID (or name, if unambiguous)|
75
- |`-y`, `--yes`|Skip confirmation and delete the add-on directly|
75
+ |`-y`, `--yes`|Skip confirmation and proceed with deletion directly|
76
76
 
77
77
  ## ➡️ `clever k8s get` <kbd>Since 4.3.0</kbd>
78
78
 
@@ -4,11 +4,11 @@ import { defineOption } from '../../lib/define-option.js';
4
4
  import { styleText } from '../../lib/style-text.js';
5
5
  import { Logger } from '../../logger.js';
6
6
  import * as Application from '../../models/application.js';
7
- import { resolveOwnerId, resolveRealId } from '../../models/ids-resolver.js';
7
+ import { resolveAddon } from '../../models/ids-resolver.js';
8
8
  import * as Log from '../../models/log.js';
9
9
  import { Deferred } from '../../models/utils.js';
10
10
  import {
11
- addonIdOption,
11
+ addonIdOrRealIdOption,
12
12
  afterOption,
13
13
  aliasOption,
14
14
  appIdOrNameOption,
@@ -36,7 +36,7 @@ export const logsCommand = defineCommand({
36
36
  app: appIdOrNameOption,
37
37
  before: beforeOption,
38
38
  after: afterOption,
39
- addon: addonIdOption,
39
+ addon: addonIdOrRealIdOption,
40
40
  format: logsFormatOption,
41
41
  },
42
42
  args: [],
@@ -57,8 +57,7 @@ export const logsCommand = defineCommand({
57
57
  const isForHuman = format === 'human';
58
58
 
59
59
  if (addonIdOrRealId != null) {
60
- const realId = await resolveRealId(addonIdOrRealId);
61
- const ownerId = await resolveOwnerId(realId);
60
+ const { ownerId, realId } = await resolveAddon(addonIdOrRealId);
62
61
  if (isForHuman) {
63
62
  Logger.println(styleText('blue', 'Waiting for addon logs…'));
64
63
  }
@@ -146,7 +146,6 @@ clever ng get-config <peer-id|peer-label> <ng-id|ng-label> [options]
146
146
 
147
147
  |Name|Description|
148
148
  |---|---|
149
- |`-F`, `--format` `<format>`|Output format (human, json) (default: human)|
150
149
  |`-o`, `--org`, `--owner` `<org-id\|org-name>`|Organisation to target by its ID (or name, if unambiguous)|
151
150
 
152
151
  ## ➡️ `clever ng link` <kbd>Since 3.12.0</kbd>
@@ -1,7 +1,7 @@
1
1
  import { defineCommand } from '../../lib/define-command.js';
2
2
  import { Logger } from '../../logger.js';
3
3
  import * as networkGroup from '../../models/ng.js';
4
- import { humanJsonOutputFormatOption, orgaIdOrNameOption } from '../global.options.js';
4
+ import { orgaIdOrNameOption } from '../global.options.js';
5
5
  import { ngExternalIdOrLabelArg, ngIdOrLabelArg } from './ng.args.js';
6
6
 
7
7
  export const ngGetConfigCommand = defineCommand({
@@ -9,24 +9,13 @@ export const ngGetConfigCommand = defineCommand({
9
9
  since: '3.12.0',
10
10
  options: {
11
11
  org: orgaIdOrNameOption,
12
- format: humanJsonOutputFormatOption,
13
12
  },
14
13
  args: [ngExternalIdOrLabelArg, ngIdOrLabelArg],
15
14
  async handler(options, peerIdOrLabel, ngIdOrLabel) {
16
- const { org, format } = options;
15
+ const { org } = options;
17
16
 
18
17
  const peerConfig = await networkGroup.getPeerConfig(peerIdOrLabel, ngIdOrLabel, org);
19
18
 
20
- switch (format) {
21
- case 'json': {
22
- Logger.printJson(peerConfig);
23
- break;
24
- }
25
- case 'human':
26
- default: {
27
- const decodedConfiguration = Buffer.from(peerConfig.configuration, 'base64').toString('utf8');
28
- Logger.println(decodedConfiguration);
29
- }
30
- }
19
+ Logger.println(peerConfig);
31
20
  },
32
21
  });
@@ -4,6 +4,6 @@ import { defineOption } from '../../lib/define-option.js';
4
4
  export const ngResourceTypeOption = defineOption({
5
5
  name: 'type',
6
6
  schema: z.enum(['NetworkGroup', 'Member', 'CleverPeer', 'ExternalPeer']).optional(),
7
- description: 'Type of resource to look for (NetworkGroup, Member, CleverPeer, ExternalPeer)',
7
+ description: 'Type of resource to look for',
8
8
  placeholder: 'resource-type',
9
9
  });
@@ -1,7 +1,7 @@
1
1
  import { deleteEmailhook } from '@clevercloud/client/esm/api/v2/notification.js';
2
2
  import { defineCommand } from '../../lib/define-command.js';
3
3
  import { Logger } from '../../logger.js';
4
- import { getOrgaIdOrUserId } from '../../models/notification.js';
4
+ import { getOwnerIdFromOrgIdOrName } from '../../models/ids-resolver.js';
5
5
  import { sendToApi } from '../../models/send-to-api.js';
6
6
  import { notificationIdArg } from '../global.args.js';
7
7
  import { orgaIdOrNameOption } from '../global.options.js';
@@ -16,7 +16,7 @@ export const notifyEmailRemoveCommand = defineCommand({
16
16
  async handler(options, notificationId) {
17
17
  const { org } = options;
18
18
 
19
- const ownerId = await getOrgaIdOrUserId(org);
19
+ const ownerId = await getOwnerIdFromOrgIdOrName(org);
20
20
  await deleteEmailhook({ ownerId, id: notificationId }).then(sendToApi);
21
21
 
22
22
  Logger.println('The notification has been successfully removed');
@@ -0,0 +1,8 @@
1
+ import { z } from 'zod';
2
+ import { defineArgument } from '../../lib/define-argument.js';
3
+
4
+ export const consumerKeyOrNameArg = defineArgument({
5
+ schema: z.string(),
6
+ description: 'OAuth consumer key (or name, if unambiguous)',
7
+ placeholder: 'consumer-key|consumer-name',
8
+ });
@@ -0,0 +1,6 @@
1
+ import { defineCommand } from '../../lib/define-command.js';
2
+
3
+ export const oauthConsumersCommand = defineCommand({
4
+ description: 'Manage OAuth consumers used with a Clever Cloud login',
5
+ since: '4.8.0',
6
+ });
@@ -0,0 +1,64 @@
1
+ import { create } from '@clevercloud/client/esm/api/v2/oauth-consumer.js';
2
+ import { z } from 'zod';
3
+ import { defineArgument } from '../../lib/define-argument.js';
4
+ import { defineCommand } from '../../lib/define-command.js';
5
+ import { promptTextOption } from '../../lib/prompts.js';
6
+ import { styleText } from '../../lib/style-text.js';
7
+ import { Logger } from '../../logger.js';
8
+ import { getOwnerIdFromOrgIdOrName } from '../../models/ids-resolver.js';
9
+ import { promptRights, rightsFromList } from '../../models/oauth-consumer.js';
10
+ import { sendToApi } from '../../models/send-to-api.js';
11
+ import { humanJsonOutputFormatOption, orgaIdOrNameOption } from '../global.options.js';
12
+ import { baseUrlOption, descriptionOption, pictureOption, rightsOption, urlOption } from './oauth-consumers.options.js';
13
+
14
+ export const oauthConsumersCreateCommand = defineCommand({
15
+ description: 'Create an OAuth consumer',
16
+ since: '4.8.0',
17
+ options: {
18
+ org: orgaIdOrNameOption,
19
+ description: descriptionOption,
20
+ url: urlOption,
21
+ picture: pictureOption,
22
+ baseUrl: baseUrlOption,
23
+ rights: rightsOption,
24
+ format: humanJsonOutputFormatOption,
25
+ },
26
+ args: [
27
+ defineArgument({
28
+ schema: z.string(),
29
+ description: 'Consumer name',
30
+ placeholder: 'name',
31
+ }),
32
+ ],
33
+ async handler(options, name) {
34
+ const { org, description, url, picture, baseUrl, rights, format } = options;
35
+
36
+ const ownerId = await getOwnerIdFromOrgIdOrName(org);
37
+
38
+ const body = {
39
+ name,
40
+ description: description ?? (await promptTextOption(descriptionOption)),
41
+ url: url ?? (await promptTextOption(urlOption)),
42
+ picture: picture ?? (await promptTextOption(pictureOption)),
43
+ baseUrl: baseUrl ?? (await promptTextOption(baseUrlOption)),
44
+ rights: rights != null ? rightsFromList(rights) : await promptRights(),
45
+ };
46
+
47
+ const oauthConsumer = await create({ id: ownerId }, body).then(sendToApi);
48
+
49
+ switch (format) {
50
+ case 'json': {
51
+ Logger.printJson(oauthConsumer);
52
+ break;
53
+ }
54
+ case 'human':
55
+ default: {
56
+ Logger.printSuccess(`OAuth consumer ${styleText(['bold', 'green'], oauthConsumer.key)} has been created!`);
57
+ Logger.println();
58
+ Logger.println(
59
+ `Retrieve the secret with ${styleText('blue', `clever oauth-consumers get ${oauthConsumer.key} --with-secret`)}`,
60
+ );
61
+ }
62
+ }
63
+ },
64
+ });
@@ -0,0 +1,33 @@
1
+ import { remove } from '@clevercloud/client/esm/api/v2/oauth-consumer.js';
2
+ import { defineCommand } from '../../lib/define-command.js';
3
+ import { confirm } from '../../lib/prompts.js';
4
+ import { styleText } from '../../lib/style-text.js';
5
+ import { Logger } from '../../logger.js';
6
+ import { resolveOauthConsumer } from '../../models/oauth-consumer.js';
7
+ import { sendToApi } from '../../models/send-to-api.js';
8
+ import { skipConfirmationOption } from '../global.options.js';
9
+ import { consumerKeyOrNameArg } from './oauth-consumers.args.js';
10
+
11
+ export const oauthConsumersDeleteCommand = defineCommand({
12
+ description: 'Delete an OAuth consumer',
13
+ since: '4.8.0',
14
+ options: {
15
+ skipConfirmation: skipConfirmationOption,
16
+ },
17
+ args: [consumerKeyOrNameArg],
18
+ async handler(options, keyOrName) {
19
+ const { skipConfirmation } = options;
20
+
21
+ const oauthConsumer = await resolveOauthConsumer(keyOrName);
22
+
23
+ if (!skipConfirmation) {
24
+ await confirm(
25
+ `Are you sure you want to delete the OAuth consumer ${styleText('blue', oauthConsumer.key)}?`,
26
+ 'OAuth consumer deletion cancelled.',
27
+ );
28
+ }
29
+
30
+ await remove({ id: oauthConsumer.ownerId, key: oauthConsumer.key }).then(sendToApi);
31
+ Logger.printSuccess(`OAuth consumer ${styleText(['bold', 'green'], oauthConsumer.key)} has been deleted!`);
32
+ },
33
+ });