clever-tools 4.4.0 → 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.
- package/bin/clever.js +208 -2128
- package/package.json +33 -25
- package/src/clever-client/auth-bridge.js +0 -9
- package/src/clever-client/drains.js +0 -17
- package/src/clever-client/operators.js +1 -1
- package/src/commands/README.md +65 -0
- package/src/commands/accesslogs/accesslogs.command.js +158 -0
- package/src/commands/accesslogs/accesslogs.docs.md +20 -0
- package/src/commands/{activity.js → activity/activity.command.js} +74 -44
- package/src/commands/activity/activity.docs.md +19 -0
- package/src/commands/addon/addon.args.js +14 -0
- package/src/commands/addon/addon.command.js +7 -0
- package/src/commands/addon/addon.create.command.js +236 -0
- package/src/commands/addon/addon.delete.command.js +32 -0
- package/src/commands/addon/addon.docs.md +156 -0
- package/src/commands/addon/addon.env.command.js +50 -0
- package/src/commands/addon/addon.list.command.js +55 -0
- package/src/commands/addon/addon.providers.command.js +45 -0
- package/src/commands/addon/addon.providers.show.command.js +99 -0
- package/src/commands/addon/addon.rename.command.js +24 -0
- package/src/commands/applications/applications.command.js +59 -0
- package/src/commands/applications/applications.docs.md +31 -0
- package/src/commands/applications/applications.list.command.js +100 -0
- package/src/commands/cancel-deploy/cancel-deploy.command.js +30 -0
- package/src/commands/cancel-deploy/cancel-deploy.docs.md +16 -0
- package/src/commands/config/config.args.js +10 -0
- package/src/commands/config/config.command.js +20 -0
- package/src/commands/config/config.docs.md +86 -0
- package/src/commands/config/config.get.command.js +21 -0
- package/src/commands/config/config.set.command.js +38 -0
- package/src/commands/config/config.update.command.js +88 -0
- package/src/commands/console/console.command.js +31 -0
- package/src/commands/console/console.docs.md +16 -0
- package/src/commands/create/create.command.js +173 -0
- package/src/commands/create/create.docs.md +27 -0
- package/src/commands/{curl.js → curl/curl.command.js} +10 -3
- package/src/commands/curl/curl.docs.md +9 -0
- package/src/commands/database/database.args.js +8 -0
- package/src/commands/database/database.backups.command.js +60 -0
- package/src/commands/database/database.backups.download.command.js +55 -0
- package/src/commands/database/database.command.js +10 -0
- package/src/commands/database/database.docs.md +52 -0
- package/src/commands/delete/delete.command.js +43 -0
- package/src/commands/delete/delete.docs.md +17 -0
- package/src/commands/deploy/deploy.command.js +166 -0
- package/src/commands/deploy/deploy.docs.md +22 -0
- package/src/commands/diag/diag.command.js +136 -0
- package/src/commands/diag/diag.docs.md +15 -0
- package/src/commands/domain/domain.add.command.js +25 -0
- package/src/commands/domain/domain.args.js +8 -0
- package/src/commands/domain/domain.command.js +38 -0
- package/src/commands/domain/domain.diag.command.js +204 -0
- package/src/commands/domain/domain.docs.md +143 -0
- package/src/commands/domain/domain.favourite.command.js +35 -0
- package/src/commands/domain/domain.favourite.set.command.js +24 -0
- package/src/commands/domain/domain.favourite.unset.command.js +23 -0
- package/src/commands/domain/domain.overview.command.js +157 -0
- package/src/commands/domain/domain.rm.command.js +25 -0
- package/src/commands/drain/drain.args.js +8 -0
- package/src/commands/drain/drain.command.js +56 -0
- package/src/commands/drain/drain.create.command.js +128 -0
- package/src/commands/drain/drain.disable.command.js +27 -0
- package/src/commands/drain/drain.docs.md +129 -0
- package/src/commands/drain/drain.enable.command.js +27 -0
- package/src/commands/drain/drain.get.command.js +38 -0
- package/src/commands/drain/drain.remove.command.js +26 -0
- package/src/commands/emails/emails.add.command.js +32 -0
- package/src/commands/emails/emails.args.js +8 -0
- package/src/commands/emails/emails.command.js +35 -0
- package/src/commands/emails/emails.docs.md +79 -0
- package/src/commands/emails/emails.open.command.js +15 -0
- package/src/commands/emails/emails.primary.command.js +29 -0
- package/src/commands/emails/emails.remove-all.command.js +54 -0
- package/src/commands/emails/emails.remove.command.js +25 -0
- package/src/commands/env/env.command.js +77 -0
- package/src/commands/env/env.docs.md +99 -0
- package/src/commands/env/env.import-vars.command.js +45 -0
- package/src/commands/env/env.import.command.js +29 -0
- package/src/commands/env/env.rm.command.js +25 -0
- package/src/commands/env/env.set.command.js +32 -0
- package/src/commands/features/features.args.js +9 -0
- package/src/commands/features/features.command.js +7 -0
- package/src/commands/features/features.disable.command.js +25 -0
- package/src/commands/features/features.docs.md +71 -0
- package/src/commands/features/features.enable.command.js +32 -0
- package/src/commands/features/features.info.command.js +27 -0
- package/src/commands/features/features.list.command.js +49 -0
- package/src/commands/global.args.js +45 -0
- package/src/commands/global.commands.js +461 -0
- package/src/commands/global.options.js +186 -0
- package/src/commands/help/help.command.js +9 -0
- package/src/commands/help/help.docs.md +9 -0
- package/src/commands/k8s/k8s.add-persistent-storage.command.js +39 -0
- package/src/commands/k8s/k8s.args.js +9 -0
- package/src/commands/k8s/k8s.command.js +12 -0
- package/src/commands/k8s/k8s.create.command.js +86 -0
- package/src/commands/k8s/k8s.delete.command.js +40 -0
- package/src/commands/k8s/k8s.docs.md +131 -0
- package/src/commands/k8s/k8s.get-kubeconfig.command.js +32 -0
- package/src/commands/k8s/k8s.get.command.js +43 -0
- package/src/commands/k8s/k8s.list.command.js +38 -0
- package/src/commands/keycloak/keycloak.command.js +17 -0
- package/src/commands/keycloak/keycloak.disable-ng.command.js +13 -0
- package/src/commands/keycloak/keycloak.docs.md +197 -0
- package/src/commands/keycloak/keycloak.enable-ng.command.js +13 -0
- package/src/commands/keycloak/keycloak.get.command.js +17 -0
- package/src/commands/keycloak/keycloak.open.command.js +13 -0
- package/src/commands/keycloak/keycloak.open.logs.command.js +13 -0
- package/src/commands/keycloak/keycloak.open.webui.command.js +13 -0
- package/src/commands/keycloak/keycloak.rebuild.command.js +13 -0
- package/src/commands/keycloak/keycloak.restart.command.js +13 -0
- package/src/commands/keycloak/keycloak.version.check.command.js +17 -0
- package/src/commands/keycloak/keycloak.version.command.js +17 -0
- package/src/commands/keycloak/keycloak.version.update.command.js +17 -0
- package/src/commands/kv/kv.command.js +99 -0
- package/src/commands/kv/kv.docs.md +27 -0
- package/src/commands/link/link.command.js +31 -0
- package/src/commands/link/link.docs.md +22 -0
- package/src/commands/{login.js → login/login.command.js} +44 -22
- package/src/commands/login/login.docs.md +16 -0
- package/src/commands/logout/logout.command.js +15 -0
- package/src/commands/logout/logout.docs.md +9 -0
- package/src/commands/logs/logs.command.js +81 -0
- package/src/commands/logs/logs.docs.md +22 -0
- package/src/commands/make-default/make-default.command.js +17 -0
- package/src/commands/make-default/make-default.docs.md +15 -0
- package/src/commands/matomo/matomo.command.js +17 -0
- package/src/commands/matomo/matomo.docs.md +109 -0
- package/src/commands/matomo/matomo.get.command.js +17 -0
- package/src/commands/matomo/matomo.open.command.js +13 -0
- package/src/commands/matomo/matomo.open.logs.command.js +13 -0
- package/src/commands/matomo/matomo.open.webui.command.js +13 -0
- package/src/commands/matomo/matomo.rebuild.command.js +13 -0
- package/src/commands/matomo/matomo.restart.command.js +13 -0
- package/src/commands/metabase/metabase.command.js +17 -0
- package/src/commands/metabase/metabase.docs.md +169 -0
- package/src/commands/metabase/metabase.get.command.js +17 -0
- package/src/commands/metabase/metabase.open.command.js +13 -0
- package/src/commands/metabase/metabase.open.logs.command.js +13 -0
- package/src/commands/metabase/metabase.open.webui.command.js +13 -0
- package/src/commands/metabase/metabase.rebuild.command.js +13 -0
- package/src/commands/metabase/metabase.restart.command.js +13 -0
- package/src/commands/metabase/metabase.version.check.command.js +17 -0
- package/src/commands/metabase/metabase.version.command.js +17 -0
- package/src/commands/metabase/metabase.version.update.command.js +17 -0
- package/src/commands/ng/ng.args.js +27 -0
- package/src/commands/ng/ng.command.js +45 -0
- package/src/commands/ng/ng.create.command.js +60 -0
- package/src/commands/ng/ng.create.external.command.js +44 -0
- package/src/commands/ng/ng.delete.command.js +22 -0
- package/src/commands/ng/ng.delete.external.command.js +25 -0
- package/src/commands/ng/ng.docs.md +214 -0
- package/src/commands/ng/ng.get-config.command.js +32 -0
- package/src/commands/ng/ng.get.command.js +22 -0
- package/src/commands/ng/ng.link.command.js +25 -0
- package/src/commands/ng/ng.options.js +9 -0
- package/src/commands/ng/ng.search.command.js +22 -0
- package/src/commands/ng/ng.unlink.command.js +25 -0
- package/src/commands/notify-email/notify-email.add.command.js +65 -0
- package/src/commands/notify-email/notify-email.command.js +61 -0
- package/src/commands/notify-email/notify-email.docs.md +60 -0
- package/src/commands/notify-email/notify-email.remove.command.js +24 -0
- package/src/commands/open/open.command.js +24 -0
- package/src/commands/open/open.docs.md +16 -0
- package/src/commands/otoroshi/otoroshi.command.js +17 -0
- package/src/commands/otoroshi/otoroshi.disable-ng.command.js +13 -0
- package/src/commands/otoroshi/otoroshi.docs.md +211 -0
- package/src/commands/otoroshi/otoroshi.enable-ng.command.js +13 -0
- package/src/commands/otoroshi/otoroshi.get-config.command.js +13 -0
- package/src/commands/otoroshi/otoroshi.get.command.js +17 -0
- package/src/commands/otoroshi/otoroshi.open.command.js +13 -0
- package/src/commands/otoroshi/otoroshi.open.logs.command.js +13 -0
- package/src/commands/otoroshi/otoroshi.open.webui.command.js +13 -0
- package/src/commands/otoroshi/otoroshi.rebuild.command.js +13 -0
- package/src/commands/otoroshi/otoroshi.restart.command.js +13 -0
- package/src/commands/otoroshi/otoroshi.version.check.command.js +17 -0
- package/src/commands/otoroshi/otoroshi.version.command.js +17 -0
- package/src/commands/otoroshi/otoroshi.version.update.command.js +17 -0
- package/src/commands/profile/profile.command.js +60 -0
- package/src/commands/profile/profile.docs.md +23 -0
- package/src/commands/profile/profile.open.command.js +12 -0
- package/src/commands/published-config/published-config.command.js +40 -0
- package/src/commands/published-config/published-config.docs.md +77 -0
- package/src/commands/published-config/published-config.import.command.js +29 -0
- package/src/commands/published-config/published-config.rm.command.js +27 -0
- package/src/commands/published-config/published-config.set.command.js +34 -0
- package/src/commands/restart/restart.command.js +77 -0
- package/src/commands/restart/restart.docs.md +21 -0
- package/src/commands/scale/scale.command.js +121 -0
- package/src/commands/scale/scale.docs.md +23 -0
- package/src/commands/service/service.command.js +91 -0
- package/src/commands/service/service.docs.md +104 -0
- package/src/commands/service/service.link-addon.command.js +24 -0
- package/src/commands/service/service.link-app.command.js +23 -0
- package/src/commands/service/service.unlink-addon.command.js +24 -0
- package/src/commands/service/service.unlink-app.command.js +23 -0
- package/src/commands/ssh/ssh.command.js +40 -0
- package/src/commands/ssh/ssh.docs.md +17 -0
- package/src/commands/ssh-keys/ssh-keys.add.command.js +41 -0
- package/src/commands/ssh-keys/ssh-keys.args.js +8 -0
- package/src/commands/ssh-keys/ssh-keys.command.js +50 -0
- package/src/commands/ssh-keys/ssh-keys.docs.md +66 -0
- package/src/commands/ssh-keys/ssh-keys.open.command.js +12 -0
- package/src/commands/ssh-keys/ssh-keys.remove-all.command.js +54 -0
- package/src/commands/ssh-keys/ssh-keys.remove.command.js +26 -0
- package/src/commands/status/status.command.js +122 -0
- package/src/commands/status/status.docs.md +17 -0
- package/src/commands/stop/stop.command.js +23 -0
- package/src/commands/stop/stop.docs.md +16 -0
- package/src/commands/tcp-redirs/tcp-redirs.add.command.js +24 -0
- package/src/commands/tcp-redirs/tcp-redirs.command.js +41 -0
- package/src/commands/tcp-redirs/tcp-redirs.docs.md +71 -0
- package/src/commands/tcp-redirs/tcp-redirs.list-namespaces.command.js +48 -0
- package/src/commands/tcp-redirs/tcp-redirs.options.js +11 -0
- package/src/commands/tcp-redirs/tcp-redirs.remove.command.js +34 -0
- package/src/commands/tokens/tokens.command.js +43 -0
- package/src/commands/tokens/tokens.create.command.js +108 -0
- package/src/commands/tokens/tokens.docs.md +50 -0
- package/src/commands/tokens/tokens.revoke.command.js +25 -0
- package/src/commands/unlink/unlink.command.js +21 -0
- package/src/commands/unlink/unlink.docs.md +15 -0
- package/src/commands/version/version.command.js +13 -0
- package/src/commands/version/version.docs.md +9 -0
- package/src/commands/webhooks/webhooks.add.command.js +51 -0
- package/src/commands/webhooks/webhooks.command.js +57 -0
- package/src/commands/webhooks/webhooks.docs.md +61 -0
- package/src/commands/webhooks/webhooks.remove.command.js +24 -0
- package/src/lib/cliparse-patched.js +192 -0
- package/src/lib/define-argument.js +7 -0
- package/src/lib/define-argument.types.d.ts +23 -0
- package/src/lib/define-command.js +7 -0
- package/src/lib/define-command.types.d.ts +85 -0
- package/src/lib/define-common.types.d.ts +18 -0
- package/src/lib/define-option.js +7 -0
- package/src/lib/define-option.types.d.ts +29 -0
- package/src/lib/get-command-info.js +86 -0
- package/src/lib/get-command-info.types.d.ts +42 -0
- package/src/lib/k8s.js +1 -1
- package/src/lib/zod-utils.js +66 -0
- package/src/models/addon.js +2 -19
- package/src/models/app_configuration.js +0 -30
- package/src/models/application.js +4 -5
- package/src/models/application_configuration.js +5 -23
- package/src/models/domain.js +34 -2
- package/src/models/exit-strategy-option.js +0 -9
- package/src/models/git.js +1 -4
- package/src/models/log-v4.js +15 -4
- package/src/models/log.js +5 -0
- package/src/models/namespaces.js +1 -2
- package/src/models/notification.js +1 -7
- package/src/parsers.js +33 -111
- package/src/command-options.js +0 -55
- package/src/command-promise-handler.js +0 -16
- package/src/commands/accesslogs.js +0 -138
- package/src/commands/addon.js +0 -391
- package/src/commands/applications.js +0 -123
- package/src/commands/cancel-deploy.js +0 -19
- package/src/commands/config.js +0 -47
- package/src/commands/console.js +0 -20
- package/src/commands/create.js +0 -129
- package/src/commands/database.js +0 -73
- package/src/commands/delete.js +0 -24
- package/src/commands/deploy.js +0 -133
- package/src/commands/diag.js +0 -126
- package/src/commands/domain.js +0 -445
- package/src/commands/drain.js +0 -164
- package/src/commands/emails.js +0 -156
- package/src/commands/env.js +0 -124
- package/src/commands/features.js +0 -87
- package/src/commands/k8s.js +0 -193
- package/src/commands/keycloak.js +0 -138
- package/src/commands/kv.js +0 -93
- package/src/commands/link.js +0 -20
- package/src/commands/logout.js +0 -8
- package/src/commands/logs.js +0 -45
- package/src/commands/makeDefault.js +0 -11
- package/src/commands/matomo.js +0 -85
- package/src/commands/metabase.js +0 -112
- package/src/commands/ng.js +0 -202
- package/src/commands/notify-email.js +0 -99
- package/src/commands/open.js +0 -13
- package/src/commands/otoroshi.js +0 -150
- package/src/commands/profile.js +0 -55
- package/src/commands/published-config.js +0 -70
- package/src/commands/restart.js +0 -52
- package/src/commands/scale.js +0 -66
- package/src/commands/service.js +0 -105
- package/src/commands/ssh-keys.js +0 -144
- package/src/commands/ssh.js +0 -20
- package/src/commands/status.js +0 -115
- package/src/commands/stop.js +0 -12
- package/src/commands/tcp-redirs.js +0 -80
- package/src/commands/tokens.js +0 -144
- package/src/commands/unlink.js +0 -14
- package/src/commands/version.js +0 -6
- package/src/commands/webhooks.js +0 -74
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { ApplicationAccessLogStream } from '@clevercloud/client/esm/streams/access-logs.js';
|
|
2
|
-
import { formatTable } from '../format-table.js';
|
|
3
|
-
import { styleText } from '../lib/style-text.js';
|
|
4
|
-
import { Logger } from '../logger.js';
|
|
5
|
-
import * as Application from '../models/application.js';
|
|
6
|
-
import { JsonArray } from '../models/json-array.js';
|
|
7
|
-
import { getHostAndTokens } from '../models/send-to-api.js';
|
|
8
|
-
import { truncateWithEllipsis } from '../models/utils.js';
|
|
9
|
-
|
|
10
|
-
// 2000 logs per 100ms maximum
|
|
11
|
-
const THROTTLE_ELEMENTS = 2000;
|
|
12
|
-
const THROTTLE_PER_IN_MILLISECONDS = 100;
|
|
13
|
-
const CITY_MAX_LENGTH = 20;
|
|
14
|
-
|
|
15
|
-
export async function accessLogs(params) {
|
|
16
|
-
// TODO: drop when add-ons are supported in API
|
|
17
|
-
if (params.options.addon) {
|
|
18
|
-
throw new Error('Access Logs are not available for add-ons yet');
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const { apiHost, tokens } = await getHostAndTokens();
|
|
22
|
-
const { alias, app: appIdOrName, format, before: until, after: since } = params.options;
|
|
23
|
-
const { ownerId, appId } = await Application.resolveId(appIdOrName, alias);
|
|
24
|
-
|
|
25
|
-
const stream = new ApplicationAccessLogStream({
|
|
26
|
-
apiHost,
|
|
27
|
-
tokens,
|
|
28
|
-
ownerId,
|
|
29
|
-
appId,
|
|
30
|
-
since,
|
|
31
|
-
until,
|
|
32
|
-
throttleElements: THROTTLE_ELEMENTS,
|
|
33
|
-
throttlePerInMilliseconds: THROTTLE_PER_IN_MILLISECONDS,
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
if (format === 'human') {
|
|
37
|
-
Logger.println(styleText('yellow', '/!\\ This feature is in Beta testing phase'));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (format === 'json' && !until) {
|
|
41
|
-
throw new Error('JSON format only works with a limiting parameter such as `before`');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// used for 'json' format
|
|
45
|
-
const jsonArray = new JsonArray();
|
|
46
|
-
|
|
47
|
-
stream
|
|
48
|
-
.on('open', () => {
|
|
49
|
-
Logger.debug(styleText('blue', `Logs stream (open) ${JSON.stringify({ appId })}`));
|
|
50
|
-
if (format === 'json') {
|
|
51
|
-
jsonArray.open();
|
|
52
|
-
}
|
|
53
|
-
})
|
|
54
|
-
.on('error', (event) => {
|
|
55
|
-
Logger.debug(styleText('red', `Logs stream (error) ${event.error.message}`));
|
|
56
|
-
})
|
|
57
|
-
.onLog((log) => {
|
|
58
|
-
switch (format) {
|
|
59
|
-
case 'json':
|
|
60
|
-
jsonArray.push(log);
|
|
61
|
-
break;
|
|
62
|
-
case 'json-stream':
|
|
63
|
-
Logger.printJson(log);
|
|
64
|
-
break;
|
|
65
|
-
case 'human':
|
|
66
|
-
default:
|
|
67
|
-
// when the connection is cut too early, or for TCP redirections, we don't have HTTP section
|
|
68
|
-
if (log.http == null) {
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
Logger.println(formatHuman(log));
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
// Properly close the stream
|
|
78
|
-
process.once('SIGINT', (signal) => stream.close(signal));
|
|
79
|
-
|
|
80
|
-
const closeReason = await stream.start();
|
|
81
|
-
|
|
82
|
-
if (format === 'json') {
|
|
83
|
-
jsonArray.close();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
Logger.debug(`stream closed: ${closeReason?.type}`);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function formatHuman(log) {
|
|
90
|
-
const { date, http, source } = log;
|
|
91
|
-
const country = source.countryCode ?? '(unknown)';
|
|
92
|
-
const hasSourceCity = source.city ?? '';
|
|
93
|
-
|
|
94
|
-
return formatTable(
|
|
95
|
-
[
|
|
96
|
-
[
|
|
97
|
-
styleText('grey', date.toISOString(date)),
|
|
98
|
-
source.ip,
|
|
99
|
-
`${country}${hasSourceCity ? '/' + truncateWithEllipsis(CITY_MAX_LENGTH, source.city) : ''}`,
|
|
100
|
-
colorStatusCode(http.response.statusCode),
|
|
101
|
-
http.request.method.toString().padEnd(4, ' ') + ' ' + http.request.path,
|
|
102
|
-
],
|
|
103
|
-
],
|
|
104
|
-
ACCESSLOG_COLUMN_WIDTHS,
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const ACCESSLOG_COLUMN_WIDTHS = [
|
|
109
|
-
'2024-06-24T08:05:43.880Z',
|
|
110
|
-
'255.255.255.255',
|
|
111
|
-
// country / city
|
|
112
|
-
2 + 1 + CITY_MAX_LENGTH,
|
|
113
|
-
'XXX',
|
|
114
|
-
// longest method name
|
|
115
|
-
'OPTIONS',
|
|
116
|
-
// path
|
|
117
|
-
];
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* @param {number} code
|
|
121
|
-
* @returns {string}
|
|
122
|
-
*/
|
|
123
|
-
function colorStatusCode(code) {
|
|
124
|
-
const codeString = code.toString();
|
|
125
|
-
if (code >= 500) {
|
|
126
|
-
return styleText('red', codeString);
|
|
127
|
-
}
|
|
128
|
-
if (code >= 400) {
|
|
129
|
-
return styleText('yellow', codeString);
|
|
130
|
-
}
|
|
131
|
-
if (code >= 300) {
|
|
132
|
-
return styleText('blue', codeString);
|
|
133
|
-
}
|
|
134
|
-
if (code >= 200) {
|
|
135
|
-
return styleText('green', codeString);
|
|
136
|
-
}
|
|
137
|
-
return codeString;
|
|
138
|
-
}
|
package/src/commands/addon.js
DELETED
|
@@ -1,391 +0,0 @@
|
|
|
1
|
-
import { styleText } from '../lib/style-text.js';
|
|
2
|
-
|
|
3
|
-
import { getAllEnvVars } from '@clevercloud/client/esm/api/v2/addon.js';
|
|
4
|
-
import { toNameEqualsValueString } from '@clevercloud/client/esm/utils/env-vars.js';
|
|
5
|
-
import dedent from 'dedent';
|
|
6
|
-
import { getOperator } from '../clever-client/operators.js';
|
|
7
|
-
import { formatTable } from '../format-table.js';
|
|
8
|
-
import { Logger } from '../logger.js';
|
|
9
|
-
import * as Addon from '../models/addon.js';
|
|
10
|
-
import { findOwnerId, parseAddonOptions } from '../models/addon.js';
|
|
11
|
-
import * as AppConfig from '../models/app_configuration.js';
|
|
12
|
-
import { conf } from '../models/configuration.js';
|
|
13
|
-
import { resolveAddonId } from '../models/ids-resolver.js';
|
|
14
|
-
import * as Organisation from '../models/organisation.js';
|
|
15
|
-
import { sendToApi } from '../models/send-to-api.js';
|
|
16
|
-
import * as User from '../models/user.js';
|
|
17
|
-
|
|
18
|
-
export async function list(params) {
|
|
19
|
-
const { org: orgaIdOrName, format } = params.options;
|
|
20
|
-
|
|
21
|
-
const ownerId = await Organisation.getId(orgaIdOrName);
|
|
22
|
-
const addons = await Addon.list(ownerId);
|
|
23
|
-
|
|
24
|
-
switch (format) {
|
|
25
|
-
case 'json': {
|
|
26
|
-
const formattedAddons = addons.map((addon) => {
|
|
27
|
-
return {
|
|
28
|
-
addonId: addon.id,
|
|
29
|
-
creationDate: addon.creationDate,
|
|
30
|
-
name: addon.name,
|
|
31
|
-
planName: addon.plan.name,
|
|
32
|
-
planSlug: addon.plan.slug,
|
|
33
|
-
providerId: addon.provider.id,
|
|
34
|
-
realId: addon.realId,
|
|
35
|
-
region: addon.region,
|
|
36
|
-
type: addon.provider.name,
|
|
37
|
-
};
|
|
38
|
-
});
|
|
39
|
-
Logger.printJson(formattedAddons);
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
case 'human':
|
|
43
|
-
default: {
|
|
44
|
-
const formattedAddons = addons.map((addon) => {
|
|
45
|
-
return [
|
|
46
|
-
addon.plan.name + ' ' + addon.provider.name,
|
|
47
|
-
addon.region,
|
|
48
|
-
styleText(['bold', 'green'], addon.name),
|
|
49
|
-
addon.id,
|
|
50
|
-
];
|
|
51
|
-
});
|
|
52
|
-
Logger.println(formatTable(formattedAddons));
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const ADDON_PROVIDERS = {
|
|
58
|
-
keycloak: {
|
|
59
|
-
name: 'Keycloak',
|
|
60
|
-
isOperator: true,
|
|
61
|
-
postCreateInstructions: `Learn more about Keycloak on Clever Cloud: ${conf.DOC_URL}/addons/keycloak/`,
|
|
62
|
-
},
|
|
63
|
-
kv: {
|
|
64
|
-
name: 'Materia KV',
|
|
65
|
-
isOperator: false,
|
|
66
|
-
status: 'beta',
|
|
67
|
-
postCreateInstructions: (addonId) => dedent`
|
|
68
|
-
${styleText('yellow', "You can easily use Materia KV with 'redis-cli', with such commands:")}
|
|
69
|
-
${styleText('blue', `source <(clever addon env ${addonId} -F shell)`)}
|
|
70
|
-
${styleText('blue', 'redis-cli -h $KV_HOST -p $KV_PORT --tls')}
|
|
71
|
-
Learn more about Materia KV on Clever Cloud: ${conf.DOC_URL}/addons/materia-kv/
|
|
72
|
-
`,
|
|
73
|
-
},
|
|
74
|
-
'addon-matomo': {
|
|
75
|
-
name: 'Matomo',
|
|
76
|
-
isOperator: true,
|
|
77
|
-
postCreateInstructions: `Learn more about Matomo on Clever Cloud: ${conf.DOC_URL}/addons/matomo/`,
|
|
78
|
-
},
|
|
79
|
-
metabase: {
|
|
80
|
-
name: 'Metabase',
|
|
81
|
-
isOperator: true,
|
|
82
|
-
postCreateInstructions: `Learn more about Metabase on Clever Cloud: ${conf.DOC_URL}/addons/metabase/`,
|
|
83
|
-
},
|
|
84
|
-
otoroshi: {
|
|
85
|
-
name: 'Otoroshi with LLM',
|
|
86
|
-
isOperator: true,
|
|
87
|
-
postCreateInstructions: `Learn more about Otoroshi with LLM on Clever Cloud: ${conf.DOC_URL}/addons/otoroshi/`,
|
|
88
|
-
},
|
|
89
|
-
'addon-pulsar': {
|
|
90
|
-
name: 'Pulsar',
|
|
91
|
-
isOperator: false,
|
|
92
|
-
postCreateInstructions: `Learn more about Pulsar on Clever Cloud: ${conf.DOC_URL}/addons/pulsar/`,
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
export async function create(params) {
|
|
97
|
-
const [providerName, name] = params.args;
|
|
98
|
-
const {
|
|
99
|
-
link: linkedAppAlias,
|
|
100
|
-
plan: planName,
|
|
101
|
-
region,
|
|
102
|
-
yes: skipConfirmation,
|
|
103
|
-
org: orgaIdOrName,
|
|
104
|
-
format,
|
|
105
|
-
'addon-version': version,
|
|
106
|
-
option: addonOptions,
|
|
107
|
-
} = params.options;
|
|
108
|
-
|
|
109
|
-
const addonToCreate = {
|
|
110
|
-
name,
|
|
111
|
-
providerName,
|
|
112
|
-
planName,
|
|
113
|
-
region,
|
|
114
|
-
skipConfirmation,
|
|
115
|
-
version,
|
|
116
|
-
addonOptions: parseAddonOptions(addonOptions),
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
const ownerId = orgaIdOrName != null ? await Organisation.getId(orgaIdOrName) : await User.getCurrentId();
|
|
120
|
-
if (linkedAppAlias != null) {
|
|
121
|
-
const linkedAppData = await AppConfig.getAppDetails({ alias: linkedAppAlias });
|
|
122
|
-
if (orgaIdOrName != null && linkedAppData.ownerId !== ownerId && format === 'human') {
|
|
123
|
-
Logger.warn(
|
|
124
|
-
'The specified application does not belong to the specified organisation. Ignoring the `--org` option',
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
addonToCreate.ownerId = linkedAppData.ownerId;
|
|
128
|
-
} else {
|
|
129
|
-
addonToCreate.ownerId = ownerId;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const newAddon = await Addon.create(addonToCreate);
|
|
133
|
-
|
|
134
|
-
if (linkedAppAlias != null) {
|
|
135
|
-
const linkedAppData = await AppConfig.getAppDetails({ alias: linkedAppAlias });
|
|
136
|
-
await Addon.link(linkedAppData.ownerId, linkedAppData.appId, { addon_id: newAddon.id });
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const provider = ADDON_PROVIDERS[providerName];
|
|
140
|
-
let statusMessage = '';
|
|
141
|
-
if (provider?.status) {
|
|
142
|
-
statusMessage = `The ${provider.name} provider is in ${provider.status} testing phase`;
|
|
143
|
-
if (provider.status === 'alpha') {
|
|
144
|
-
statusMessage += ". Don't store sensitive or production grade data.";
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// JSON format
|
|
149
|
-
if (format === 'json') {
|
|
150
|
-
const jsonAddon = {
|
|
151
|
-
id: newAddon.id,
|
|
152
|
-
realId: newAddon.realId,
|
|
153
|
-
name: newAddon.name,
|
|
154
|
-
env: newAddon.env,
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
if (provider?.status) {
|
|
158
|
-
jsonAddon.availability = provider.status;
|
|
159
|
-
jsonAddon.message = statusMessage;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
Logger.printJson(jsonAddon);
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// Human format
|
|
167
|
-
if (linkedAppAlias != null) {
|
|
168
|
-
Logger.println(`Add-on created and linked to application ${linkedAppAlias} successfully!`);
|
|
169
|
-
} else {
|
|
170
|
-
Logger.println('Add-on created successfully!');
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
Logger.println(`ID: ${newAddon.id}`);
|
|
174
|
-
Logger.println(`Real ID: ${newAddon.realId}`);
|
|
175
|
-
Logger.println(`Name: ${newAddon.name}`);
|
|
176
|
-
|
|
177
|
-
const operator = ADDON_PROVIDERS[providerName]?.isOperator
|
|
178
|
-
? await getOperator({ provider: providerName, realId: newAddon.realId }).then(sendToApi)
|
|
179
|
-
: null;
|
|
180
|
-
|
|
181
|
-
if (operator) {
|
|
182
|
-
if (operator.accessUrl) {
|
|
183
|
-
Logger.println();
|
|
184
|
-
Logger.println(`Your ${ADDON_PROVIDERS[providerName].name} is starting:`);
|
|
185
|
-
Logger.println(` - Access it: ${operator.accessUrl}`);
|
|
186
|
-
Logger.println(` - Manage it: ${conf.GOTO_URL}/${newAddon.id}`);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (operator.initialCredentials) {
|
|
190
|
-
if (providerName === 'keycloak') {
|
|
191
|
-
Logger.println();
|
|
192
|
-
Logger.println("An initial account has been created, you'll be invited to change the password at first login:");
|
|
193
|
-
Logger.println(` - Admin user name: ${operator.initialCredentials.user}`);
|
|
194
|
-
Logger.println(` - Temporary password: ${operator.initialCredentials.password}`);
|
|
195
|
-
}
|
|
196
|
-
if (providerName === 'otoroshi') {
|
|
197
|
-
Logger.println();
|
|
198
|
-
Logger.println(
|
|
199
|
-
'An initial account has been created, change the password at first login (Security -> Administrators -> Edit user):',
|
|
200
|
-
);
|
|
201
|
-
Logger.println(` - Admin user name: ${operator.initialCredentials.user}`);
|
|
202
|
-
Logger.println(` - Password: ${operator.initialCredentials.password}`);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if (provider?.postCreateInstructions) {
|
|
208
|
-
Logger.println();
|
|
209
|
-
|
|
210
|
-
if (statusMessage !== '') {
|
|
211
|
-
Logger.println(styleText('yellow', `/!\\ ${statusMessage}`));
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (typeof provider.postCreateInstructions === 'function') {
|
|
215
|
-
Logger.println(provider.postCreateInstructions(newAddon.id));
|
|
216
|
-
} else {
|
|
217
|
-
Logger.println(provider.postCreateInstructions);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
export async function deleteAddon(params) {
|
|
223
|
-
const { yes: skipConfirmation, org: orgaIdOrName } = params.options;
|
|
224
|
-
const [addon] = params.args;
|
|
225
|
-
|
|
226
|
-
let ownerId = await Organisation.getId(orgaIdOrName);
|
|
227
|
-
if (ownerId == null && addon.addon_id != null) {
|
|
228
|
-
ownerId = await Addon.findOwnerId(ownerId, addon.addon_id);
|
|
229
|
-
}
|
|
230
|
-
if (ownerId == null && addon.addon_name != null) {
|
|
231
|
-
const foundAddon = await Addon.findByName(addon.addon_name);
|
|
232
|
-
ownerId = foundAddon.orgaId;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
await Addon.deleteAddon(ownerId, addon, skipConfirmation);
|
|
236
|
-
|
|
237
|
-
Logger.println(`Addon ${addon.addon_id || addon.addon_name} successfully deleted`);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
export async function rename(params) {
|
|
241
|
-
const [addon, newName] = params.args;
|
|
242
|
-
const { org: orgaIdOrName } = params.options;
|
|
243
|
-
|
|
244
|
-
const ownerId = await Organisation.getId(orgaIdOrName);
|
|
245
|
-
await Addon.rename(ownerId, addon, newName);
|
|
246
|
-
|
|
247
|
-
Logger.println(`Addon ${addon.addon_id || addon.addon_name} successfully renamed to ${newName}`);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
export async function listProviders(params) {
|
|
251
|
-
const { format } = params.options;
|
|
252
|
-
|
|
253
|
-
const providers = await Addon.listProviders();
|
|
254
|
-
|
|
255
|
-
switch (format) {
|
|
256
|
-
case 'json': {
|
|
257
|
-
const formattedProviders = providers.map((provider) => ({
|
|
258
|
-
id: provider.id,
|
|
259
|
-
name: provider.name,
|
|
260
|
-
shortDesc: provider.shortDesc,
|
|
261
|
-
regions: provider.regions,
|
|
262
|
-
plans: provider.plans.map((plan) => ({
|
|
263
|
-
id: plan.id,
|
|
264
|
-
name: plan.name,
|
|
265
|
-
slug: plan.slug,
|
|
266
|
-
})),
|
|
267
|
-
}));
|
|
268
|
-
Logger.printJson(formattedProviders);
|
|
269
|
-
break;
|
|
270
|
-
}
|
|
271
|
-
case 'human':
|
|
272
|
-
default: {
|
|
273
|
-
const formattedProviders = providers.map((provider) => {
|
|
274
|
-
return [styleText('bold', provider.id), provider.name, provider.shortDesc || ''];
|
|
275
|
-
});
|
|
276
|
-
Logger.println(formatTable(formattedProviders));
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
export async function showProvider(params) {
|
|
282
|
-
const [providerName] = params.args;
|
|
283
|
-
const { format } = params.options;
|
|
284
|
-
|
|
285
|
-
const provider = await Addon.getProvider(providerName);
|
|
286
|
-
const providerInfos = await Addon.getProviderInfos(providerName);
|
|
287
|
-
|
|
288
|
-
const formattedPlans = [...provider.plans]
|
|
289
|
-
.sort((a, b) => a.price - b.price)
|
|
290
|
-
.map((plan) => {
|
|
291
|
-
const formattedFeatures = plan.features
|
|
292
|
-
.map((feature) => ({
|
|
293
|
-
name: feature.name,
|
|
294
|
-
value: feature.value,
|
|
295
|
-
}))
|
|
296
|
-
.sort((a, b) => a.name.localeCompare(b.name));
|
|
297
|
-
|
|
298
|
-
const formattedPlan = {
|
|
299
|
-
id: plan.id,
|
|
300
|
-
name: plan.name,
|
|
301
|
-
slug: plan.slug,
|
|
302
|
-
features: formattedFeatures,
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
if (providerInfos != null) {
|
|
306
|
-
const planType = plan.features.find(({ name }) => name.toLowerCase() === 'type');
|
|
307
|
-
if (planType != null && planType.value.toLowerCase() === 'dedicated') {
|
|
308
|
-
const planVersions = Object.keys(providerInfos.dedicated);
|
|
309
|
-
formattedPlan.versions = planVersions.map((version) => {
|
|
310
|
-
return {
|
|
311
|
-
version,
|
|
312
|
-
isDefault: version === providerInfos.defaultDedicatedVersion,
|
|
313
|
-
options: providerInfos.dedicated[version].features.map((feature) => ({
|
|
314
|
-
name: feature.name,
|
|
315
|
-
enabledByDefault: feature.enabled,
|
|
316
|
-
})),
|
|
317
|
-
};
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
return formattedPlan;
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
const formattedProvider = {
|
|
326
|
-
id: provider.id,
|
|
327
|
-
name: provider.name,
|
|
328
|
-
shortDesc: provider.shortDesc,
|
|
329
|
-
regions: provider.regions,
|
|
330
|
-
plans: formattedPlans,
|
|
331
|
-
};
|
|
332
|
-
|
|
333
|
-
switch (format) {
|
|
334
|
-
case 'json': {
|
|
335
|
-
Logger.printJson(formattedProvider);
|
|
336
|
-
break;
|
|
337
|
-
}
|
|
338
|
-
case 'human':
|
|
339
|
-
default: {
|
|
340
|
-
Logger.println(styleText('bold', formattedProvider.id));
|
|
341
|
-
Logger.println(`${formattedProvider.name}: ${formattedProvider.shortDesc}`);
|
|
342
|
-
Logger.println();
|
|
343
|
-
Logger.println(`Available regions: ${formattedProvider.regions.join(', ')}`);
|
|
344
|
-
Logger.println();
|
|
345
|
-
Logger.println('Available plans');
|
|
346
|
-
|
|
347
|
-
formattedProvider.plans.forEach((plan) => {
|
|
348
|
-
Logger.println(`Plan ${styleText('bold', plan.slug)}`);
|
|
349
|
-
plan.features.forEach(({ name, value }) => Logger.println(` ${name}: ${value}`));
|
|
350
|
-
|
|
351
|
-
if (plan.versions != null) {
|
|
352
|
-
Logger.println(
|
|
353
|
-
` Available versions: ${plan.versions.map(({ version, isDefault }) => (isDefault ? `${version} (default)` : version)).join(', ')}`,
|
|
354
|
-
);
|
|
355
|
-
plan.versions.forEach(({ version, options }) => {
|
|
356
|
-
Logger.println(` Options for version ${version}:`);
|
|
357
|
-
options.forEach(({ name, enabledByDefault }) => {
|
|
358
|
-
Logger.println(` ${name}: default=${enabledByDefault}`);
|
|
359
|
-
});
|
|
360
|
-
});
|
|
361
|
-
}
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
export async function env(params) {
|
|
368
|
-
const { org, format } = params.options;
|
|
369
|
-
const [addonIdOrRealId] = params.args;
|
|
370
|
-
|
|
371
|
-
const addonId = await resolveAddonId(addonIdOrRealId);
|
|
372
|
-
const ownerId = await findOwnerId(org, addonId);
|
|
373
|
-
|
|
374
|
-
const envFromAddon = await getAllEnvVars({ id: ownerId, addonId }).then(sendToApi);
|
|
375
|
-
|
|
376
|
-
switch (format) {
|
|
377
|
-
case 'json': {
|
|
378
|
-
const envFromAddonJson = Object.fromEntries(envFromAddon.map(({ name, value }) => [name, value]));
|
|
379
|
-
Logger.println(JSON.stringify(envFromAddonJson, null, 2));
|
|
380
|
-
break;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
case 'shell':
|
|
384
|
-
Logger.println(toNameEqualsValueString(envFromAddon, { addExports: true }));
|
|
385
|
-
break;
|
|
386
|
-
|
|
387
|
-
case 'human':
|
|
388
|
-
default:
|
|
389
|
-
Logger.println(toNameEqualsValueString(envFromAddon, { addExports: false }));
|
|
390
|
-
}
|
|
391
|
-
}
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { styleText } from '../lib/style-text.js';
|
|
2
|
-
|
|
3
|
-
import { formatTable } from '../format-table.js';
|
|
4
|
-
import { Logger } from '../logger.js';
|
|
5
|
-
import * as AppConfig from '../models/app_configuration.js';
|
|
6
|
-
import * as Application from '../models/application.js';
|
|
7
|
-
import * as Organisation from '../models/organisation.js';
|
|
8
|
-
import { truncateWithEllipsis } from '../models/utils.js';
|
|
9
|
-
|
|
10
|
-
export async function list(params) {
|
|
11
|
-
const { 'only-aliases': onlyAliases, json } = params.options;
|
|
12
|
-
|
|
13
|
-
const { apps } = await AppConfig.loadApplicationConf();
|
|
14
|
-
|
|
15
|
-
const formattedApps = formatApps(apps, onlyAliases, json);
|
|
16
|
-
Logger.println(formattedApps);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function formatApps(apps, onlyAliases, json) {
|
|
20
|
-
if (json) {
|
|
21
|
-
if (onlyAliases) {
|
|
22
|
-
apps = apps.map((a) => a.alias);
|
|
23
|
-
}
|
|
24
|
-
return JSON.stringify(apps, null, 2);
|
|
25
|
-
} else {
|
|
26
|
-
if (onlyAliases) {
|
|
27
|
-
return apps.map((a) => a.alias).join('\n');
|
|
28
|
-
} else {
|
|
29
|
-
return apps
|
|
30
|
-
.map((app) => {
|
|
31
|
-
const sshUrl = app.git_ssh_url ?? app.deploy_url.replace('https://', 'git+ssh://git@');
|
|
32
|
-
return [
|
|
33
|
-
`Application ${app.name}`,
|
|
34
|
-
` alias: ${styleText('bold', app.alias)}`,
|
|
35
|
-
` ID: ${app.app_id}`,
|
|
36
|
-
` deployment URL: ${app.deploy_url}`,
|
|
37
|
-
` git+ssh URL: ${sshUrl}`,
|
|
38
|
-
].join('\n');
|
|
39
|
-
})
|
|
40
|
-
.join('\n\n');
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export async function listAll(params) {
|
|
46
|
-
const { org: orgaIdOrName, format } = params.options;
|
|
47
|
-
|
|
48
|
-
const linkedApps = await AppConfig.loadApplicationConf().then((conf) => conf.apps);
|
|
49
|
-
|
|
50
|
-
const ownerId = orgaIdOrName != null && orgaIdOrName.orga_name !== '' ? await Organisation.getId(orgaIdOrName) : null;
|
|
51
|
-
|
|
52
|
-
const allAppsPerOrg = await Application.getAllApps(ownerId);
|
|
53
|
-
|
|
54
|
-
// For each app, we try to find a corresponding local alias in the configuration file
|
|
55
|
-
const allAppsWithAliasPerOrg = allAppsPerOrg.map((org) => {
|
|
56
|
-
const applicationsWithAlias = org.applications.map((app) => {
|
|
57
|
-
const foundAlias = linkedApps.find((a) => a.app_id === app.app_id)?.alias;
|
|
58
|
-
return { ...app, alias: foundAlias ?? '' };
|
|
59
|
-
});
|
|
60
|
-
return { ...org, applications: applicationsWithAlias };
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
switch (format) {
|
|
64
|
-
case 'json': {
|
|
65
|
-
Logger.printJson(allAppsWithAliasPerOrg);
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
case 'human':
|
|
69
|
-
default: {
|
|
70
|
-
const headers = ['APPLICATION ID', 'NAME', 'TYPE', 'ZONE', 'LOCAL ALIAS'];
|
|
71
|
-
const appNameWidth = 42;
|
|
72
|
-
|
|
73
|
-
// We calculate the maximum width of each column to format the table
|
|
74
|
-
const allApps = allAppsWithAliasPerOrg.flatMap((org) => org.applications);
|
|
75
|
-
const columnWidths = [
|
|
76
|
-
getPropertyMaxWidth(allApps, 'app_id'),
|
|
77
|
-
appNameWidth,
|
|
78
|
-
getPropertyMaxWidth(allApps, 'type'),
|
|
79
|
-
getPropertyMaxWidth(allApps, 'zone'),
|
|
80
|
-
getPropertyMaxWidth(allApps, 'alias'),
|
|
81
|
-
];
|
|
82
|
-
|
|
83
|
-
allAppsWithAliasPerOrg.forEach((org) => {
|
|
84
|
-
Logger.println();
|
|
85
|
-
|
|
86
|
-
const applicationsPlural = org.applications.length !== 1 ? 'applications' : 'application';
|
|
87
|
-
const punctuation = org.applications.length > 0 ? ':' : '';
|
|
88
|
-
|
|
89
|
-
Logger.println(
|
|
90
|
-
styleText(
|
|
91
|
-
'blue',
|
|
92
|
-
`• Organization '${org.name}' (${org.id}) with ${org.applications.length} ${applicationsPlural}${punctuation}`,
|
|
93
|
-
),
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
if (org.applications.length > 0) {
|
|
97
|
-
Logger.println();
|
|
98
|
-
Logger.println(
|
|
99
|
-
formatTable(
|
|
100
|
-
[
|
|
101
|
-
headers,
|
|
102
|
-
...org.applications.map((app) => [
|
|
103
|
-
app.app_id,
|
|
104
|
-
truncateWithEllipsis(appNameWidth, app.name),
|
|
105
|
-
app.type,
|
|
106
|
-
app.zone,
|
|
107
|
-
app.alias,
|
|
108
|
-
]),
|
|
109
|
-
],
|
|
110
|
-
columnWidths,
|
|
111
|
-
),
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function getPropertyMaxWidth(array, propertyName) {
|
|
122
|
-
return Math.max(...array.map((o) => o[propertyName].length));
|
|
123
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { cancelDeployment, getAllDeployments } from '@clevercloud/client/esm/api/v2/application.js';
|
|
2
|
-
import { styleText } from '../lib/style-text.js';
|
|
3
|
-
import { Logger } from '../logger.js';
|
|
4
|
-
import * as Application from '../models/application.js';
|
|
5
|
-
import { sendToApi } from '../models/send-to-api.js';
|
|
6
|
-
|
|
7
|
-
export async function cancelDeploy(params) {
|
|
8
|
-
const { alias, app: appIdOrName } = params.options;
|
|
9
|
-
const { ownerId, appId } = await Application.resolveId(appIdOrName, alias);
|
|
10
|
-
|
|
11
|
-
const deployments = await getAllDeployments({ id: ownerId, appId, limit: 1 }).then(sendToApi);
|
|
12
|
-
|
|
13
|
-
if (deployments.length === 0 || deployments[0].action !== 'DEPLOY' || deployments[0].state !== 'WIP') {
|
|
14
|
-
throw new Error('There is no ongoing deployment for this application');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
await cancelDeployment({ id: ownerId, appId, deploymentId: deployments[0].id }).then(sendToApi);
|
|
18
|
-
Logger.printSuccess(`Deployment ${styleText(['bold', 'green'], deployments[0].uuid)} successfully cancelled!`);
|
|
19
|
-
}
|