clever-tools 4.4.1 → 4.5.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 (291) hide show
  1. package/bin/clever.js +208 -2125
  2. package/package.json +33 -25
  3. package/src/commands/README.md +65 -0
  4. package/src/commands/accesslogs/accesslogs.command.js +158 -0
  5. package/src/commands/accesslogs/accesslogs.docs.md +20 -0
  6. package/src/commands/{activity.js → activity/activity.command.js} +74 -44
  7. package/src/commands/activity/activity.docs.md +19 -0
  8. package/src/commands/addon/addon.args.js +14 -0
  9. package/src/commands/addon/addon.command.js +7 -0
  10. package/src/commands/addon/addon.create.command.js +236 -0
  11. package/src/commands/addon/addon.delete.command.js +32 -0
  12. package/src/commands/addon/addon.docs.md +156 -0
  13. package/src/commands/addon/addon.env.command.js +50 -0
  14. package/src/commands/addon/addon.list.command.js +55 -0
  15. package/src/commands/addon/addon.providers.command.js +45 -0
  16. package/src/commands/addon/addon.providers.show.command.js +99 -0
  17. package/src/commands/addon/addon.rename.command.js +24 -0
  18. package/src/commands/applications/applications.command.js +59 -0
  19. package/src/commands/applications/applications.docs.md +31 -0
  20. package/src/commands/applications/applications.list.command.js +100 -0
  21. package/src/commands/cancel-deploy/cancel-deploy.command.js +30 -0
  22. package/src/commands/cancel-deploy/cancel-deploy.docs.md +16 -0
  23. package/src/commands/config/config.args.js +10 -0
  24. package/src/commands/config/config.command.js +20 -0
  25. package/src/commands/config/config.docs.md +86 -0
  26. package/src/commands/config/config.get.command.js +21 -0
  27. package/src/commands/config/config.set.command.js +38 -0
  28. package/src/commands/config/config.update.command.js +88 -0
  29. package/src/commands/console/console.command.js +31 -0
  30. package/src/commands/console/console.docs.md +16 -0
  31. package/src/commands/create/create.command.js +173 -0
  32. package/src/commands/create/create.docs.md +27 -0
  33. package/src/commands/{curl.js → curl/curl.command.js} +10 -3
  34. package/src/commands/curl/curl.docs.md +9 -0
  35. package/src/commands/database/database.args.js +8 -0
  36. package/src/commands/database/database.backups.command.js +60 -0
  37. package/src/commands/database/database.backups.download.command.js +55 -0
  38. package/src/commands/database/database.command.js +10 -0
  39. package/src/commands/database/database.docs.md +52 -0
  40. package/src/commands/delete/delete.command.js +43 -0
  41. package/src/commands/delete/delete.docs.md +17 -0
  42. package/src/commands/deploy/deploy.command.js +166 -0
  43. package/src/commands/deploy/deploy.docs.md +22 -0
  44. package/src/commands/diag/diag.command.js +136 -0
  45. package/src/commands/diag/diag.docs.md +15 -0
  46. package/src/commands/domain/domain.add.command.js +25 -0
  47. package/src/commands/domain/domain.args.js +8 -0
  48. package/src/commands/domain/domain.command.js +38 -0
  49. package/src/commands/domain/domain.diag.command.js +204 -0
  50. package/src/commands/domain/domain.docs.md +143 -0
  51. package/src/commands/domain/domain.favourite.command.js +35 -0
  52. package/src/commands/domain/domain.favourite.set.command.js +24 -0
  53. package/src/commands/domain/domain.favourite.unset.command.js +23 -0
  54. package/src/commands/domain/domain.overview.command.js +157 -0
  55. package/src/commands/domain/domain.rm.command.js +25 -0
  56. package/src/commands/drain/drain.args.js +8 -0
  57. package/src/commands/drain/drain.command.js +56 -0
  58. package/src/commands/drain/drain.create.command.js +128 -0
  59. package/src/commands/drain/drain.disable.command.js +27 -0
  60. package/src/commands/drain/drain.docs.md +129 -0
  61. package/src/commands/drain/drain.enable.command.js +27 -0
  62. package/src/commands/drain/drain.get.command.js +38 -0
  63. package/src/commands/drain/drain.remove.command.js +26 -0
  64. package/src/commands/emails/emails.add.command.js +32 -0
  65. package/src/commands/emails/emails.args.js +8 -0
  66. package/src/commands/emails/emails.command.js +35 -0
  67. package/src/commands/emails/emails.docs.md +79 -0
  68. package/src/commands/emails/emails.open.command.js +15 -0
  69. package/src/commands/emails/emails.primary.command.js +29 -0
  70. package/src/commands/emails/emails.remove-all.command.js +54 -0
  71. package/src/commands/emails/emails.remove.command.js +25 -0
  72. package/src/commands/env/env.command.js +77 -0
  73. package/src/commands/env/env.docs.md +99 -0
  74. package/src/commands/env/env.import-vars.command.js +45 -0
  75. package/src/commands/env/env.import.command.js +29 -0
  76. package/src/commands/env/env.rm.command.js +25 -0
  77. package/src/commands/env/env.set.command.js +32 -0
  78. package/src/commands/features/features.args.js +9 -0
  79. package/src/commands/features/features.command.js +7 -0
  80. package/src/commands/features/features.disable.command.js +25 -0
  81. package/src/commands/features/features.docs.md +71 -0
  82. package/src/commands/features/features.enable.command.js +32 -0
  83. package/src/commands/features/features.info.command.js +27 -0
  84. package/src/commands/features/features.list.command.js +49 -0
  85. package/src/commands/global.args.js +45 -0
  86. package/src/commands/global.commands.js +461 -0
  87. package/src/commands/global.options.js +186 -0
  88. package/src/commands/help/help.command.js +9 -0
  89. package/src/commands/help/help.docs.md +9 -0
  90. package/src/commands/k8s/k8s.add-persistent-storage.command.js +39 -0
  91. package/src/commands/k8s/k8s.args.js +9 -0
  92. package/src/commands/k8s/k8s.command.js +12 -0
  93. package/src/commands/k8s/k8s.create.command.js +86 -0
  94. package/src/commands/k8s/k8s.delete.command.js +40 -0
  95. package/src/commands/k8s/k8s.docs.md +131 -0
  96. package/src/commands/k8s/k8s.get-kubeconfig.command.js +32 -0
  97. package/src/commands/k8s/k8s.get.command.js +43 -0
  98. package/src/commands/k8s/k8s.list.command.js +38 -0
  99. package/src/commands/keycloak/keycloak.command.js +17 -0
  100. package/src/commands/keycloak/keycloak.disable-ng.command.js +13 -0
  101. package/src/commands/keycloak/keycloak.docs.md +197 -0
  102. package/src/commands/keycloak/keycloak.enable-ng.command.js +13 -0
  103. package/src/commands/keycloak/keycloak.get.command.js +17 -0
  104. package/src/commands/keycloak/keycloak.open.command.js +13 -0
  105. package/src/commands/keycloak/keycloak.open.logs.command.js +13 -0
  106. package/src/commands/keycloak/keycloak.open.webui.command.js +13 -0
  107. package/src/commands/keycloak/keycloak.rebuild.command.js +13 -0
  108. package/src/commands/keycloak/keycloak.restart.command.js +13 -0
  109. package/src/commands/keycloak/keycloak.version.check.command.js +17 -0
  110. package/src/commands/keycloak/keycloak.version.command.js +17 -0
  111. package/src/commands/keycloak/keycloak.version.update.command.js +17 -0
  112. package/src/commands/kv/kv.command.js +99 -0
  113. package/src/commands/kv/kv.docs.md +27 -0
  114. package/src/commands/link/link.command.js +31 -0
  115. package/src/commands/link/link.docs.md +22 -0
  116. package/src/commands/{login.js → login/login.command.js} +44 -22
  117. package/src/commands/login/login.docs.md +16 -0
  118. package/src/commands/logout/logout.command.js +15 -0
  119. package/src/commands/logout/logout.docs.md +9 -0
  120. package/src/commands/logs/logs.command.js +81 -0
  121. package/src/commands/logs/logs.docs.md +22 -0
  122. package/src/commands/make-default/make-default.command.js +17 -0
  123. package/src/commands/make-default/make-default.docs.md +15 -0
  124. package/src/commands/matomo/matomo.command.js +17 -0
  125. package/src/commands/matomo/matomo.docs.md +109 -0
  126. package/src/commands/matomo/matomo.get.command.js +17 -0
  127. package/src/commands/matomo/matomo.open.command.js +13 -0
  128. package/src/commands/matomo/matomo.open.logs.command.js +13 -0
  129. package/src/commands/matomo/matomo.open.webui.command.js +13 -0
  130. package/src/commands/matomo/matomo.rebuild.command.js +13 -0
  131. package/src/commands/matomo/matomo.restart.command.js +13 -0
  132. package/src/commands/metabase/metabase.command.js +17 -0
  133. package/src/commands/metabase/metabase.docs.md +169 -0
  134. package/src/commands/metabase/metabase.get.command.js +17 -0
  135. package/src/commands/metabase/metabase.open.command.js +13 -0
  136. package/src/commands/metabase/metabase.open.logs.command.js +13 -0
  137. package/src/commands/metabase/metabase.open.webui.command.js +13 -0
  138. package/src/commands/metabase/metabase.rebuild.command.js +13 -0
  139. package/src/commands/metabase/metabase.restart.command.js +13 -0
  140. package/src/commands/metabase/metabase.version.check.command.js +17 -0
  141. package/src/commands/metabase/metabase.version.command.js +17 -0
  142. package/src/commands/metabase/metabase.version.update.command.js +17 -0
  143. package/src/commands/ng/ng.args.js +27 -0
  144. package/src/commands/ng/ng.command.js +45 -0
  145. package/src/commands/ng/ng.create.command.js +60 -0
  146. package/src/commands/ng/ng.create.external.command.js +44 -0
  147. package/src/commands/ng/ng.delete.command.js +22 -0
  148. package/src/commands/ng/ng.delete.external.command.js +25 -0
  149. package/src/commands/ng/ng.docs.md +214 -0
  150. package/src/commands/ng/ng.get-config.command.js +32 -0
  151. package/src/commands/ng/ng.get.command.js +22 -0
  152. package/src/commands/ng/ng.link.command.js +25 -0
  153. package/src/commands/ng/ng.options.js +9 -0
  154. package/src/commands/ng/ng.search.command.js +22 -0
  155. package/src/commands/ng/ng.unlink.command.js +25 -0
  156. package/src/commands/notify-email/notify-email.add.command.js +65 -0
  157. package/src/commands/notify-email/notify-email.command.js +61 -0
  158. package/src/commands/notify-email/notify-email.docs.md +60 -0
  159. package/src/commands/notify-email/notify-email.remove.command.js +24 -0
  160. package/src/commands/open/open.command.js +24 -0
  161. package/src/commands/open/open.docs.md +16 -0
  162. package/src/commands/otoroshi/otoroshi.command.js +17 -0
  163. package/src/commands/otoroshi/otoroshi.disable-ng.command.js +13 -0
  164. package/src/commands/otoroshi/otoroshi.docs.md +211 -0
  165. package/src/commands/otoroshi/otoroshi.enable-ng.command.js +13 -0
  166. package/src/commands/otoroshi/otoroshi.get-config.command.js +13 -0
  167. package/src/commands/otoroshi/otoroshi.get.command.js +17 -0
  168. package/src/commands/otoroshi/otoroshi.open.command.js +13 -0
  169. package/src/commands/otoroshi/otoroshi.open.logs.command.js +13 -0
  170. package/src/commands/otoroshi/otoroshi.open.webui.command.js +13 -0
  171. package/src/commands/otoroshi/otoroshi.rebuild.command.js +13 -0
  172. package/src/commands/otoroshi/otoroshi.restart.command.js +13 -0
  173. package/src/commands/otoroshi/otoroshi.version.check.command.js +17 -0
  174. package/src/commands/otoroshi/otoroshi.version.command.js +17 -0
  175. package/src/commands/otoroshi/otoroshi.version.update.command.js +17 -0
  176. package/src/commands/profile/profile.command.js +60 -0
  177. package/src/commands/profile/profile.docs.md +23 -0
  178. package/src/commands/profile/profile.open.command.js +12 -0
  179. package/src/commands/published-config/published-config.command.js +40 -0
  180. package/src/commands/published-config/published-config.docs.md +77 -0
  181. package/src/commands/published-config/published-config.import.command.js +29 -0
  182. package/src/commands/published-config/published-config.rm.command.js +27 -0
  183. package/src/commands/published-config/published-config.set.command.js +34 -0
  184. package/src/commands/restart/restart.command.js +77 -0
  185. package/src/commands/restart/restart.docs.md +21 -0
  186. package/src/commands/scale/scale.command.js +121 -0
  187. package/src/commands/scale/scale.docs.md +23 -0
  188. package/src/commands/service/service.command.js +91 -0
  189. package/src/commands/service/service.docs.md +104 -0
  190. package/src/commands/service/service.link-addon.command.js +24 -0
  191. package/src/commands/service/service.link-app.command.js +23 -0
  192. package/src/commands/service/service.unlink-addon.command.js +24 -0
  193. package/src/commands/service/service.unlink-app.command.js +23 -0
  194. package/src/commands/ssh/ssh.command.js +40 -0
  195. package/src/commands/ssh/ssh.docs.md +17 -0
  196. package/src/commands/ssh-keys/ssh-keys.add.command.js +41 -0
  197. package/src/commands/ssh-keys/ssh-keys.args.js +8 -0
  198. package/src/commands/ssh-keys/ssh-keys.command.js +50 -0
  199. package/src/commands/ssh-keys/ssh-keys.docs.md +66 -0
  200. package/src/commands/ssh-keys/ssh-keys.open.command.js +12 -0
  201. package/src/commands/ssh-keys/ssh-keys.remove-all.command.js +54 -0
  202. package/src/commands/ssh-keys/ssh-keys.remove.command.js +26 -0
  203. package/src/commands/status/status.command.js +122 -0
  204. package/src/commands/status/status.docs.md +17 -0
  205. package/src/commands/stop/stop.command.js +23 -0
  206. package/src/commands/stop/stop.docs.md +16 -0
  207. package/src/commands/tcp-redirs/tcp-redirs.add.command.js +24 -0
  208. package/src/commands/tcp-redirs/tcp-redirs.command.js +41 -0
  209. package/src/commands/tcp-redirs/tcp-redirs.docs.md +71 -0
  210. package/src/commands/tcp-redirs/tcp-redirs.list-namespaces.command.js +48 -0
  211. package/src/commands/tcp-redirs/tcp-redirs.options.js +11 -0
  212. package/src/commands/tcp-redirs/tcp-redirs.remove.command.js +34 -0
  213. package/src/commands/tokens/tokens.command.js +43 -0
  214. package/src/commands/tokens/tokens.create.command.js +108 -0
  215. package/src/commands/tokens/tokens.docs.md +50 -0
  216. package/src/commands/tokens/tokens.revoke.command.js +25 -0
  217. package/src/commands/unlink/unlink.command.js +21 -0
  218. package/src/commands/unlink/unlink.docs.md +15 -0
  219. package/src/commands/version/version.command.js +13 -0
  220. package/src/commands/version/version.docs.md +9 -0
  221. package/src/commands/webhooks/webhooks.add.command.js +51 -0
  222. package/src/commands/webhooks/webhooks.command.js +57 -0
  223. package/src/commands/webhooks/webhooks.docs.md +61 -0
  224. package/src/commands/webhooks/webhooks.remove.command.js +24 -0
  225. package/src/lib/cliparse-patched.js +192 -0
  226. package/src/lib/define-argument.js +7 -0
  227. package/src/lib/define-argument.types.d.ts +23 -0
  228. package/src/lib/define-command.js +7 -0
  229. package/src/lib/define-command.types.d.ts +85 -0
  230. package/src/lib/define-common.types.d.ts +18 -0
  231. package/src/lib/define-option.js +7 -0
  232. package/src/lib/define-option.types.d.ts +29 -0
  233. package/src/lib/get-command-info.js +86 -0
  234. package/src/lib/get-command-info.types.d.ts +42 -0
  235. package/src/lib/zod-utils.js +66 -0
  236. package/src/models/addon.js +2 -3
  237. package/src/models/application.js +4 -5
  238. package/src/models/application_configuration.js +5 -23
  239. package/src/models/domain.js +34 -2
  240. package/src/models/exit-strategy-option.js +0 -9
  241. package/src/models/git.js +1 -4
  242. package/src/models/log-v4.js +5 -0
  243. package/src/models/log.js +5 -0
  244. package/src/models/namespaces.js +1 -2
  245. package/src/models/notification.js +1 -7
  246. package/src/parsers.js +33 -92
  247. package/src/command-options.js +0 -55
  248. package/src/command-promise-handler.js +0 -16
  249. package/src/commands/accesslogs.js +0 -138
  250. package/src/commands/addon.js +0 -391
  251. package/src/commands/applications.js +0 -123
  252. package/src/commands/cancel-deploy.js +0 -19
  253. package/src/commands/config.js +0 -47
  254. package/src/commands/console.js +0 -20
  255. package/src/commands/create.js +0 -129
  256. package/src/commands/database.js +0 -73
  257. package/src/commands/delete.js +0 -24
  258. package/src/commands/deploy.js +0 -133
  259. package/src/commands/diag.js +0 -126
  260. package/src/commands/domain.js +0 -445
  261. package/src/commands/drain.js +0 -164
  262. package/src/commands/emails.js +0 -156
  263. package/src/commands/env.js +0 -124
  264. package/src/commands/features.js +0 -87
  265. package/src/commands/k8s.js +0 -193
  266. package/src/commands/keycloak.js +0 -138
  267. package/src/commands/kv.js +0 -93
  268. package/src/commands/link.js +0 -20
  269. package/src/commands/logout.js +0 -8
  270. package/src/commands/logs.js +0 -45
  271. package/src/commands/makeDefault.js +0 -11
  272. package/src/commands/matomo.js +0 -85
  273. package/src/commands/metabase.js +0 -112
  274. package/src/commands/ng.js +0 -202
  275. package/src/commands/notify-email.js +0 -99
  276. package/src/commands/open.js +0 -13
  277. package/src/commands/otoroshi.js +0 -149
  278. package/src/commands/profile.js +0 -55
  279. package/src/commands/published-config.js +0 -70
  280. package/src/commands/restart.js +0 -52
  281. package/src/commands/scale.js +0 -66
  282. package/src/commands/service.js +0 -105
  283. package/src/commands/ssh-keys.js +0 -144
  284. package/src/commands/ssh.js +0 -20
  285. package/src/commands/status.js +0 -115
  286. package/src/commands/stop.js +0 -12
  287. package/src/commands/tcp-redirs.js +0 -80
  288. package/src/commands/tokens.js +0 -144
  289. package/src/commands/unlink.js +0 -14
  290. package/src/commands/version.js +0 -6
  291. package/src/commands/webhooks.js +0 -74
@@ -1,156 +0,0 @@
1
- import {
2
- todo_addEmailAddress as addEmailAddress,
3
- todo_removeEmailAddress as removeEmailAddress,
4
- } from '@clevercloud/client/esm/api/v2/user.js';
5
- import { confirm } from '../lib/prompts.js';
6
- import { styleText } from '../lib/style-text.js';
7
- import { Logger } from '../logger.js';
8
- import { getUserEmailAddresses } from '../models/emails.js';
9
- import { sendToApi } from '../models/send-to-api.js';
10
- import { openBrowser } from '../models/utils.js';
11
-
12
- /**
13
- * Show primary and secondary email addresses of the current user
14
- * @param {object} params The command parameters
15
- * @param {string} params.options.format The output format
16
- */
17
- export async function list(params) {
18
- const { format } = params.options;
19
- const addresses = await getUserEmailAddresses();
20
-
21
- switch (format) {
22
- case 'json': {
23
- Logger.printJson(addresses);
24
- break;
25
- }
26
- case 'human':
27
- default: {
28
- Logger.println('✉️ Primary email address:');
29
- Logger.println(` • ${styleText('green', addresses.primary)}`);
30
- if (addresses.secondary.length > 0) {
31
- Logger.println();
32
- Logger.println(`✉️ ${addresses.secondary.length} secondary email address(es):`);
33
- addresses.secondary.forEach((address) => Logger.println(` • ${styleText('blue', address)}`));
34
- }
35
- }
36
- }
37
- }
38
-
39
- /**
40
- * Add a secondary email address to the current user
41
- * @param {object} params The command parameters
42
- * @param {Array<string>} params.args
43
- */
44
- export async function addSecondary(params) {
45
- const [secondaryAddress] = params.args;
46
-
47
- const secondaryAddressEncoded = encodeURIComponent(secondaryAddress);
48
- try {
49
- await addEmailAddress({ email: secondaryAddressEncoded }).then(sendToApi);
50
- Logger.printSuccess(
51
- `The server sent a confirmation email to ${secondaryAddress} to validate your secondary address`,
52
- );
53
- } catch (e) {
54
- switch (e?.responseBody?.id) {
55
- case 101:
56
- throw new Error('This address already belongs to your account');
57
- case 550:
58
- throw new Error('The format of this address is invalid');
59
- case 1004:
60
- throw new Error('This address belongs to another account');
61
- default:
62
- throw e;
63
- }
64
- }
65
- }
66
-
67
- /**
68
- * Set the primary email address of the current user
69
- * @param {object} params The command parameters
70
- * @param {Array<string>} params.args
71
- */
72
- export async function setPrimary(params) {
73
- const [newPrimaryAddress] = params.args;
74
-
75
- const addresses = await getUserEmailAddresses();
76
-
77
- if (addresses.primary === newPrimaryAddress) {
78
- throw new Error('This address is already the primary one');
79
- }
80
-
81
- if (!addresses.secondary.includes(newPrimaryAddress)) {
82
- throw new Error('This address must be added as a secondary address before marking it as primary');
83
- }
84
-
85
- const newPrimaryEmailEncoded = encodeURIComponent(newPrimaryAddress);
86
- await addEmailAddress({ email: newPrimaryEmailEncoded }, { make_primary: true }).then(sendToApi);
87
-
88
- Logger.printSuccess(`Primary address updated to ${newPrimaryAddress} successfully`);
89
- }
90
-
91
- /**
92
- * Remove a secondary email address from the current user
93
- * @param {object} params The command parameters
94
- * @param {Array<string>} params.args
95
- */
96
- export async function removeSecondary(params) {
97
- const [addressToRemove] = params.args;
98
-
99
- const addresses = await getUserEmailAddresses();
100
-
101
- if (!addresses.secondary.includes(addressToRemove)) {
102
- throw new Error("This address is not part of the secondary addresses of the current user, it can't be removed");
103
- }
104
-
105
- const addressToRemoveEncoded = encodeURIComponent(addressToRemove);
106
- await removeEmailAddress({ email: addressToRemoveEncoded }).then(sendToApi);
107
-
108
- Logger.printSuccess(`Secondary address ${addressToRemove} removed successfully`);
109
- }
110
-
111
- /**
112
- * Remove all secondary email addresses from the current user
113
- * @param {object} params The command parameters
114
- * @param {object} params.options The command options
115
- * @param {boolean} params.options.yes The user confirmation
116
- */
117
- export async function removeAllSecondary(params) {
118
- if (!params.options.yes) {
119
- await confirm('Are you sure you want to remove all your secondary addresses?', 'No secondary addresses removed');
120
- }
121
-
122
- const addresses = await getUserEmailAddresses();
123
-
124
- if (addresses.secondary.length === 0) {
125
- Logger.println('No secondary address to remove');
126
- return;
127
- }
128
-
129
- const results = await Promise.all(
130
- addresses.secondary.map((addressToRemove) => {
131
- const addressToRemoveEncoded = encodeURIComponent(addressToRemove);
132
- return removeEmailAddress({ email: addressToRemoveEncoded })
133
- .then(sendToApi)
134
- .then(() => [true, addressToRemove])
135
- .catch(() => [false, addressToRemove]);
136
- }),
137
- );
138
-
139
- if (results.every(([isRemoved]) => isRemoved)) {
140
- Logger.printSuccess('All secondary addresses were removed successfully');
141
- } else {
142
- const addressesWithErrors = results
143
- .filter(([isRemoved]) => !isRemoved)
144
- .map(([_, address]) => address)
145
- .join(', ');
146
- throw new Error(`Some errors occured while removing these addresses: ${addressesWithErrors}`);
147
- }
148
- }
149
-
150
- /**
151
- * Open the email addresses management page of the Console in your browser
152
- * @returns {Promise<void>} A promise that resolves when the page is opened
153
- */
154
- export function openConsole() {
155
- return openBrowser('/users/me/emails', 'Opening the email addresses management page of the Console in your browser');
156
- }
@@ -1,124 +0,0 @@
1
- import {
2
- getAllEnvVars,
3
- getAllEnvVarsForAddons,
4
- getAllEnvVarsForDependencies,
5
- removeEnvVar,
6
- updateAllEnvVars,
7
- updateEnvVar,
8
- } from '@clevercloud/client/esm/api/v2/application.js';
9
- import { toNameEqualsValueString, validateName } from '@clevercloud/client/esm/utils/env-vars.js';
10
- import { styleText } from '../lib/style-text.js';
11
- import { Logger } from '../logger.js';
12
- import * as Application from '../models/application.js';
13
- import { sendToApi } from '../models/send-to-api.js';
14
- import * as variables from '../models/variables.js';
15
-
16
- export async function list(params) {
17
- const { alias, app: appIdOrName, 'add-export': addExportsOption, format } = params.options;
18
- const { ownerId, appId } = await Application.resolveId(appIdOrName, alias);
19
-
20
- const [envFromApp, envFromAddons, envFromDeps] = await Promise.all([
21
- getAllEnvVars({ id: ownerId, appId }).then(sendToApi),
22
- getAllEnvVarsForAddons({ id: ownerId, appId }).then(sendToApi),
23
- getAllEnvVarsForDependencies({ id: ownerId, appId }).then(sendToApi),
24
- ]);
25
-
26
- switch (format) {
27
- case 'json': {
28
- Logger.printJson({
29
- env: envFromApp,
30
- fromAddons: envFromAddons.map((addon) => ({
31
- addonId: addon.addon_id,
32
- addonName: addon.addon_name,
33
- env: addon.env,
34
- })),
35
- fromDependencies: envFromDeps.map((dep) => ({
36
- addonId: dep.app_id,
37
- addonName: dep.app_name,
38
- env: dep.env,
39
- })),
40
- });
41
- break;
42
- }
43
- case 'shell':
44
- case 'human':
45
- default: {
46
- if (addExportsOption) {
47
- Logger.println(styleText('yellow', '`--add-export` option is deprecated. Use `--format shell` instead.'));
48
- }
49
-
50
- const addExports = addExportsOption || format === 'shell';
51
-
52
- Logger.println('# Manually set env variables');
53
- Logger.println(toNameEqualsValueString(envFromApp, { addExports }));
54
-
55
- envFromAddons.forEach((addon) => {
56
- Logger.println('# Addon ' + addon.addon_name);
57
- Logger.println(toNameEqualsValueString(addon.env, { addExports }));
58
- });
59
-
60
- envFromDeps.forEach((dep) => {
61
- Logger.println('# Dependency ' + dep.app_name);
62
- Logger.println(toNameEqualsValueString(dep.env, { addExports }));
63
- });
64
- }
65
- }
66
- }
67
-
68
- export async function set(params) {
69
- const [envName, value] = params.args;
70
- const { alias, app: appIdOrName } = params.options;
71
-
72
- const nameIsValid = validateName(envName);
73
- if (!nameIsValid) {
74
- throw new Error(`Environment variable name ${envName} is invalid`);
75
- }
76
-
77
- const { ownerId, appId } = await Application.resolveId(appIdOrName, alias);
78
-
79
- await updateEnvVar({ id: ownerId, appId, envName }, { value }).then(sendToApi);
80
-
81
- Logger.println('Your environment variable has been successfully saved');
82
- }
83
-
84
- export async function rm(params) {
85
- const [envName] = params.args;
86
- const { alias, app: appIdOrName } = params.options;
87
- const { ownerId, appId } = await Application.resolveId(appIdOrName, alias);
88
-
89
- await removeEnvVar({ id: ownerId, appId, envName }).then(sendToApi);
90
-
91
- Logger.println('Your environment variable has been successfully removed');
92
- }
93
-
94
- export async function importEnv(params) {
95
- const { alias, app: appIdOrName, json } = params.options;
96
- const format = json ? 'json' : 'name-equals-value';
97
- const { ownerId, appId } = await Application.resolveId(appIdOrName, alias);
98
-
99
- const envVars = await variables.readVariablesFromStdin(format);
100
- await updateAllEnvVars({ id: ownerId, appId }, envVars).then(sendToApi);
101
-
102
- Logger.println('Environment variables have been set');
103
- }
104
-
105
- export async function importVarsFromLocalEnv(params) {
106
- const [envNames] = params.args;
107
- const { alias, app: appIdOrName } = params.options;
108
-
109
- for (const envName of envNames) {
110
- const nameIsValid = validateName(envName);
111
- if (!nameIsValid) {
112
- throw new Error(`Environment variable name ${envName} is invalid`);
113
- }
114
- }
115
-
116
- const { ownerId, appId } = await Application.resolveId(appIdOrName, alias);
117
-
118
- for (const envName of envNames) {
119
- const value = process.env[envName] || '';
120
- await updateEnvVar({ id: ownerId, appId, envName }, { value }).then(sendToApi);
121
- }
122
-
123
- Logger.println('Your environment variables have been successfully saved');
124
- }
@@ -1,87 +0,0 @@
1
- import { EXPERIMENTAL_FEATURES } from '../experimental-features.js';
2
- import { formatTable } from '../format-table.js';
3
- import { Logger } from '../logger.js';
4
- import { getFeatures, setFeature } from '../models/configuration.js';
5
-
6
- export async function list(params) {
7
- const { format } = params.options;
8
-
9
- const featuresConf = await getFeatures();
10
- // Add status from configuration file and remove instructions
11
- const features = Object.entries(EXPERIMENTAL_FEATURES).map(([id, feature]) => {
12
- const enabled = featuresConf[id] === true;
13
- return {
14
- id,
15
- status: feature.status,
16
- description: feature.description,
17
- enabled,
18
- };
19
- });
20
-
21
- // For each feature, print the object with the id, status, description and enabled
22
- switch (format) {
23
- case 'json': {
24
- Logger.printJson(features);
25
- break;
26
- }
27
- case 'human':
28
- default: {
29
- const headers = ['ID', 'STATUS', 'DESCRIPTION', 'ENABLED'];
30
-
31
- Logger.println(
32
- formatTable([
33
- headers,
34
- ...features.map((feature) => [feature.id, feature.status, feature.description, feature.enabled]),
35
- ]),
36
- );
37
- }
38
- }
39
- }
40
-
41
- export async function info(params) {
42
- const { feature } = params.namedArgs;
43
- const availableFeatures = Object.keys(EXPERIMENTAL_FEATURES);
44
-
45
- if (!availableFeatures.includes(feature)) {
46
- throw new Error(`Unavailable feature: ${feature}`);
47
- }
48
-
49
- Logger.println(EXPERIMENTAL_FEATURES[feature].instructions);
50
- }
51
-
52
- export async function enable(params) {
53
- const { features } = params.namedArgs;
54
- const availableFeatures = Object.keys(EXPERIMENTAL_FEATURES);
55
-
56
- const unknownFeatures = features.filter((feature) => !availableFeatures.includes(feature));
57
- if (unknownFeatures.length > 0) {
58
- throw new Error(`Unavailable feature(s): ${unknownFeatures.join(', ')}`);
59
- }
60
-
61
- for (const featureName of features) {
62
- await setFeature(featureName, true);
63
- Logger.println(`Experimental feature '${featureName}' enabled`);
64
- }
65
-
66
- if (features.length === 1) {
67
- Logger.println(EXPERIMENTAL_FEATURES[features[0]].instructions);
68
- } else {
69
- Logger.println();
70
- Logger.println("To learn more about these experimental features, use 'clever features info FEATURE_NAME'");
71
- }
72
- }
73
-
74
- export async function disable(params) {
75
- const { features } = params.namedArgs;
76
- const availableFeatures = Object.keys(EXPERIMENTAL_FEATURES);
77
-
78
- const unknownFeatures = features.filter((feature) => !availableFeatures.includes(feature));
79
- if (unknownFeatures.length > 0) {
80
- throw new Error(`Unavailable feature(s): ${unknownFeatures.join(', ')}`);
81
- }
82
-
83
- for (const featureName of features) {
84
- await setFeature(featureName, false);
85
- Logger.println(`Experimental feature '${featureName}' disabled`);
86
- }
87
- }
@@ -1,193 +0,0 @@
1
- import { typewriterLogo } from '../lib/ascii.js';
2
- import {
3
- getK8sCluster,
4
- isK8sClusterActive,
5
- k8sAddPersistentStorage,
6
- k8sCreate,
7
- k8sDelete,
8
- k8sGetConfig,
9
- k8sList,
10
- } from '../lib/k8s.js';
11
- import { confirm } from '../lib/prompts.js';
12
- import { styleText } from '../lib/style-text.js';
13
- import { Logger } from '../logger.js';
14
-
15
- const DEPLOY_POLL_DELAY_MS = 10000;
16
-
17
- export async function create(params) {
18
- const clusterName = params.args[0];
19
- const orgIdOrName = params.options.org;
20
-
21
- try {
22
- const cluster = await k8sCreate(clusterName, orgIdOrName);
23
-
24
- if (params.options.watch) {
25
- await typewriterLogo();
26
-
27
- let deployedCluster = cluster;
28
- while (deployedCluster.status !== 'ACTIVE' && deployedCluster.status !== 'FAILED') {
29
- Logger.println(
30
- `⏳ Cluster status: ${styleText('yellow', deployedCluster.status)}. Waiting for ${DEPLOY_POLL_DELAY_MS / 1000}s before checking again...`,
31
- );
32
- await new Promise((resolve) => setTimeout(resolve, DEPLOY_POLL_DELAY_MS));
33
-
34
- deployedCluster = await getK8sCluster(orgIdOrName, cluster.id);
35
- }
36
-
37
- Logger.println('');
38
- switch (deployedCluster.status) {
39
- case 'ACTIVE':
40
- Logger.printSuccess(
41
- `Cluster ${styleText('green', `${deployedCluster.name} (${deployedCluster.id})`)} deployed successfully`,
42
- );
43
- break;
44
- case 'FAILED':
45
- throw new Error(
46
- `Cluster ${styleText('red', `${deployedCluster.name} (${deployedCluster.id})`)} deployment failed`,
47
- );
48
- default:
49
- throw new Error(`Unexpected cluster status: ${deployedCluster.status}`);
50
- }
51
- } else {
52
- Logger.println(`🚀 Cluster ${styleText('white', `${cluster.name} (${cluster.id})`)} is being deployed`);
53
- }
54
-
55
- const orgMessageComplement = orgIdOrName ? `--org "${orgIdOrName.orga_id || orgIdOrName.orga_name}"` : '';
56
-
57
- Logger.println('');
58
- Logger.println(
59
- `You can get its information with ${styleText('blue', `clever k8s get ${cluster.id} ${orgMessageComplement}`)}`,
60
- );
61
- } catch (error) {
62
- if (error.responseBody?.code === 'clever.core.quota-exceeded') {
63
- throw new Error(
64
- 'Failed to create Kubernetes cluster: your quota exceeded, contact support to increase your quota',
65
- );
66
- } else {
67
- throw new Error(error.message);
68
- }
69
- }
70
- }
71
-
72
- export async function del(params) {
73
- const [clusterIdOrName] = params.args;
74
- const { org: orgIdOrName, yes: confirmDeletion } = params.options;
75
-
76
- let proceedDeletion;
77
- if (confirmDeletion) {
78
- proceedDeletion = true;
79
- } else {
80
- proceedDeletion = await confirm(
81
- `Are you sure you want to delete the Kubernetes cluster ${styleText(
82
- 'blue',
83
- clusterIdOrName.addon_name || clusterIdOrName.operator_id,
84
- )}?`,
85
- 'Kubernetes cluster deletion cancelled.',
86
- );
87
- }
88
-
89
- if (proceedDeletion) {
90
- await k8sDelete(orgIdOrName, clusterIdOrName);
91
- Logger.printSuccess(
92
- `Kubernetes cluster ${styleText('green', clusterIdOrName.addon_name || clusterIdOrName.operator_id)} successfully deleted`,
93
- );
94
- }
95
- }
96
-
97
- export async function list(params) {
98
- const { format, org: orgIdOrName } = params.options;
99
- const clusters = await k8sList(orgIdOrName, format);
100
-
101
- switch (format) {
102
- case 'json':
103
- Logger.printJson(clusters);
104
- break;
105
- case 'human':
106
- default:
107
- if (clusters.length === 0) {
108
- Logger.println(`🔎 No cluster found, create one with ${styleText('blue', `clever k8s create`)} command`);
109
- return;
110
- }
111
-
112
- Logger.println(`🔎 Found ${clusters.length} cluster${clusters.length > 1 ? 's' : ''}:`);
113
-
114
- Object.values(clusters).forEach((c) => {
115
- Logger.println(` • ${styleText('white', `${c.name} (${c.id})`)} - ${c.status}`);
116
- });
117
- break;
118
- }
119
- }
120
-
121
- export async function get(params) {
122
- const [clusterIdOrName] = params.args;
123
- const { format, org: orgIdOrName } = params.options;
124
-
125
- const k8sInfo = await getK8sCluster(orgIdOrName, clusterIdOrName);
126
-
127
- switch (format) {
128
- case 'json':
129
- Logger.printJson(k8sInfo);
130
- break;
131
- case 'human':
132
- default:
133
- console.table({
134
- Name: k8sInfo.name,
135
- ID: k8sInfo.id,
136
- Version: k8sInfo.version,
137
- Status: k8sInfo.status,
138
- });
139
-
140
- Logger.println('');
141
- const orgMessageComplement = orgIdOrName ? `--org "${orgIdOrName.orga_id || orgIdOrName.orga_name}"` : '';
142
-
143
- Logger.println(
144
- `Once ACTIVE, get the kubeconfig with ${styleText('blue', `clever k8s get-kubeconfig ${k8sInfo.id} ${orgMessageComplement}`)}`,
145
- );
146
- break;
147
- }
148
- }
149
-
150
- export async function addPersistentStorage(params) {
151
- const [clusterIdOrName] = params.args;
152
- const orgIdOrName = params.options.org;
153
-
154
- if ((await isK8sClusterActive(orgIdOrName, clusterIdOrName)) === false) {
155
- Logger.printInfo(
156
- 'Persistent storage can only be added to deployed clusters, wait for the deployment to finish and try again',
157
- );
158
-
159
- const orgMessageComplement = orgIdOrName ? `--org "${orgIdOrName.orga_id || orgIdOrName.orga_name}"` : '';
160
- Logger.println(
161
- `Check with ${styleText('blue', `clever k8s get ${clusterIdOrName.addon_name || clusterIdOrName.operator_id} ${orgMessageComplement}`)}`,
162
- );
163
- return;
164
- }
165
-
166
- try {
167
- await k8sAddPersistentStorage(orgIdOrName, clusterIdOrName);
168
- Logger.printSuccess(
169
- `Persistent storage successfully activated on cluster ${styleText('green', clusterIdOrName.addon_name || clusterIdOrName.operator_id)}`,
170
- );
171
- } catch (error) {
172
- Logger.error("Failed to add persistent storage, check if it's not already activated");
173
- }
174
- }
175
-
176
- export async function getConfig(params) {
177
- const [clusterIdOrName] = params.args;
178
- const orgIdOrName = params.options.org;
179
-
180
- if ((await isK8sClusterActive(orgIdOrName, clusterIdOrName)) !== true) {
181
- Logger.printInfo(
182
- 'Kubeconfig can only be retrieved from deployed clusters, wait for the deployment to finish and try again',
183
- );
184
-
185
- const orgMessageComplement = orgIdOrName ? `--org "${orgIdOrName.orga_id || orgIdOrName.orga_name}"` : '';
186
- Logger.println(
187
- `Check with ${styleText('blue', `clever k8s get ${clusterIdOrName.addon_name || clusterIdOrName.operator_id} ${orgMessageComplement}`)}`,
188
- );
189
- return;
190
- }
191
-
192
- console.log(await k8sGetConfig(orgIdOrName, clusterIdOrName));
193
- }
@@ -1,138 +0,0 @@
1
- import {
2
- operatorCheckVersion,
3
- operatorList,
4
- operatorNgDisable,
5
- operatorNgEnable,
6
- operatorOpen,
7
- operatorOpenLogs,
8
- operatorOpenWebUi,
9
- operatorPrint,
10
- operatorReboot,
11
- operatorRebuild,
12
- operatorUpdateVersion,
13
- } from '../lib/operator-commands.js';
14
-
15
- /**
16
- * Check the version of a Keycloak operator
17
- * @param {object} params The command's parameters
18
- * @param {string} params.args[0] The operator's name or ID
19
- * @param {string} params.options.format The output format
20
- * @returns {Promise<void>}
21
- */
22
- export async function checkVersion(params) {
23
- const [addonIdOrName] = params.args;
24
- const { format } = params.options;
25
- await operatorCheckVersion('keycloak', addonIdOrName, format);
26
- }
27
-
28
- /**
29
- * Update the version of a Keycloak operator
30
- * @param {object} params The command's parameters
31
- * @param {string} params.args[0] The operator's name or ID
32
- * @returns {Promise<void>}
33
- */
34
- export async function updateVersion(params) {
35
- const [addonIdOrName] = params.args;
36
- const { target } = params.options;
37
- await operatorUpdateVersion('keycloak', target, addonIdOrName);
38
- }
39
-
40
- /**
41
- * Get the details of a Keycloak operator
42
- * @param {object} params The command's parameters
43
- * @param {string} params.args[0] The operator's name or ID
44
- * @param {string} params.options.format The output format
45
- * @returns {Promise<void>}
46
- */
47
- export async function get(params) {
48
- const [addonIdOrName] = params.args;
49
- const { format } = params.options;
50
- await operatorPrint('keycloak', addonIdOrName, format);
51
- }
52
-
53
- /**
54
- * List all Keycloak operators
55
- * @returns {Promise<void>}
56
- */
57
- export async function list(params) {
58
- await operatorList('keycloak', params.options.format);
59
- }
60
-
61
- /**
62
- * Unlink a Keycloak operator from a Network Group
63
- * @param {object} params The command's parameters
64
- * @param {string} params.args[0] The operator's name or ID
65
- * @returns {Promise<void>}
66
- * @throws {Error} If the Network Group feature is already disabled
67
- */
68
- export async function ngDisable(params) {
69
- const [addonIdOrName] = params.args;
70
- await operatorNgDisable('keycloak', addonIdOrName);
71
- }
72
-
73
- /**
74
- * Link a Keycloak operator to a Network Group
75
- * @param {object} params The command's parameters
76
- * @param {string} params.args[0] The operator's name or ID
77
- * @returns {Promise<void>}
78
- * @throws {Error} If the Network Group feature is already enabled
79
- */
80
- export async function ngEnable(params) {
81
- const [addonIdOrName] = params.args;
82
- await operatorNgEnable('keycloak', addonIdOrName);
83
- }
84
-
85
- /**
86
- * Open a Keycloak operator dashboard in the Clever Cloud Console
87
- * @param {object} params The command's parameters
88
- * @param {string} params.args[0] The operator's name or ID
89
- * @returns {Promise<void>}
90
- */
91
- export async function open(params) {
92
- const [addonIdOrName] = params.args;
93
- await operatorOpen('keycloak', addonIdOrName);
94
- }
95
-
96
- /**
97
- * Open the Logs section of a Keycloak Operator application in the Clever Cloud Console
98
- * @param {object} params The command's parameters
99
- * @param {string} params.args[0] The operator's name or ID
100
- * @returns {Promise<void>}
101
- */
102
- export async function openLogs(params) {
103
- const [addonIdOrName] = params.args;
104
- await operatorOpenLogs('keycloak', addonIdOrName);
105
- }
106
-
107
- /**
108
- * Open the Web UI of a Keycloak Operator application in the Clever Cloud Console
109
- * @param {object} params The command's parameters
110
- * @param {string} params.args[0] The operator's name or ID
111
- * @returns {Promise<void>}
112
- */
113
- export async function openWebUi(params) {
114
- const [addonIdOrName] = params.args;
115
- await operatorOpenWebUi('keycloak', addonIdOrName);
116
- }
117
-
118
- /**
119
- * Restart a Keycloak operator
120
- * @param {object} params The command's parameters
121
- * @param {string} params.args[0] The operator's name or ID
122
- * @returns {Promise<void>}
123
- */
124
- export async function reboot(params) {
125
- const [addonIdOrName] = params.args;
126
- await operatorReboot('keycloak', addonIdOrName);
127
- }
128
-
129
- /**
130
- * Rebuild a Keycloak operator
131
- * @param {object} params The command's parameters
132
- * @param {string} params.args[0] The operator's name or ID
133
- * @returns {Promise<void>}
134
- */
135
- export async function rebuild(params) {
136
- const [addonIdOrName] = params.args;
137
- await operatorRebuild('keycloak', addonIdOrName);
138
- }