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
package/src/commands/status.js
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { getAllInstances, get as getApplication } from '@clevercloud/client/esm/api/v2/application.js';
|
|
2
|
-
import _ from 'lodash';
|
|
3
|
-
import { styleText } from '../lib/style-text.js';
|
|
4
|
-
import { Logger } from '../logger.js';
|
|
5
|
-
import * as Application from '../models/application.js';
|
|
6
|
-
import { sendToApi } from '../models/send-to-api.js';
|
|
7
|
-
|
|
8
|
-
export async function status(params) {
|
|
9
|
-
const { alias, app: appIdOrName, format } = params.options;
|
|
10
|
-
const { ownerId, appId } = await Application.resolveId(appIdOrName, alias);
|
|
11
|
-
|
|
12
|
-
const instances = await getAllInstances({ id: ownerId, appId }).then(sendToApi);
|
|
13
|
-
const app = await getApplication({ id: ownerId, appId }).then(sendToApi);
|
|
14
|
-
|
|
15
|
-
const status = computeStatus(instances, app);
|
|
16
|
-
|
|
17
|
-
switch (format) {
|
|
18
|
-
case 'json': {
|
|
19
|
-
Logger.printJson(status);
|
|
20
|
-
break;
|
|
21
|
-
}
|
|
22
|
-
case 'human':
|
|
23
|
-
default: {
|
|
24
|
-
const statusMessage =
|
|
25
|
-
status.status === 'running'
|
|
26
|
-
? `${styleText(['bold', 'green'], 'running')} ${displayInstances(status.instances, status.commit)}`
|
|
27
|
-
: styleText(['bold', 'red'], 'stopped');
|
|
28
|
-
|
|
29
|
-
Logger.println(`${status.name}: ${statusMessage}`);
|
|
30
|
-
Logger.println(`Type: ${status.type.name}`);
|
|
31
|
-
Logger.println(`Executed as: ${styleText('bold', status.lifetime)}`);
|
|
32
|
-
if (status.deploymentInProgress) {
|
|
33
|
-
Logger.println(
|
|
34
|
-
`Deployment in progress ${displayInstances(status.deploymentInProgress.instances, status.deploymentInProgress.commit)}`,
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
Logger.println();
|
|
38
|
-
Logger.println('Scalability:');
|
|
39
|
-
Logger.println(
|
|
40
|
-
` Auto scalability: ${status.scalability.enabled ? styleText('green', 'enabled') : styleText('red', 'disabled')}`,
|
|
41
|
-
);
|
|
42
|
-
Logger.println(` Scalers: ${styleText('bold', formatScalability(status.scalability.horizontal))}`);
|
|
43
|
-
Logger.println(` Sizes: ${styleText('bold', formatScalability(status.scalability.vertical))}`);
|
|
44
|
-
Logger.println(
|
|
45
|
-
` Dedicated build: ${status.separateBuild ? styleText('bold', status.buildFlavor) : styleText('red', 'disabled')}`,
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function displayInstances(instances, commit) {
|
|
52
|
-
return `(${instances.map((instance) => `${instance.count}*${instance.flavor}`)}, Commit: ${commit || 'N/A'})`;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function computeStatus(instances, app) {
|
|
56
|
-
const upInstances = _.filter(instances, ({ state }) => state === 'UP');
|
|
57
|
-
const isUp = !_.isEmpty(upInstances);
|
|
58
|
-
const upCommit = _(upInstances).map('commit').head();
|
|
59
|
-
|
|
60
|
-
const deployingInstances = _.filter(instances, ({ state }) => state === 'DEPLOYING');
|
|
61
|
-
const isDeploying = !_.isEmpty(deployingInstances);
|
|
62
|
-
const deployingCommit = _(deployingInstances).map('commit').head();
|
|
63
|
-
|
|
64
|
-
const { minFlavor, maxFlavor, minInstances, maxInstances } = app.instance;
|
|
65
|
-
|
|
66
|
-
const scalabilityEnabled = minFlavor.name !== maxFlavor.name || minInstances !== maxInstances;
|
|
67
|
-
|
|
68
|
-
const status = {
|
|
69
|
-
id: app.id,
|
|
70
|
-
name: app.name,
|
|
71
|
-
type: {
|
|
72
|
-
name: app.instance.variant.name,
|
|
73
|
-
slug: app.instance.variant.slug,
|
|
74
|
-
},
|
|
75
|
-
lifetime: app.instance.lifetime,
|
|
76
|
-
status: isUp ? 'running' : 'stopped',
|
|
77
|
-
commit: upCommit,
|
|
78
|
-
instances: groupInstances(upInstances),
|
|
79
|
-
scalability: {
|
|
80
|
-
enabled: scalabilityEnabled,
|
|
81
|
-
vertical: { min: minFlavor.name, max: maxFlavor.name },
|
|
82
|
-
horizontal: { min: minInstances, max: maxInstances },
|
|
83
|
-
},
|
|
84
|
-
separateBuild: app.separateBuild,
|
|
85
|
-
buildFlavor: app.buildFlavor.name,
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
if (isDeploying) {
|
|
89
|
-
status.deploymentInProgress = {
|
|
90
|
-
commit: deployingCommit,
|
|
91
|
-
instances: groupInstances(deployingInstances),
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return status;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* @param {number} min
|
|
100
|
-
* @param {number} max
|
|
101
|
-
* @returns {string}
|
|
102
|
-
*/
|
|
103
|
-
function formatScalability({ min, max }) {
|
|
104
|
-
return min === max ? min.toString() : `${min} to ${max}`;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function groupInstances(instances) {
|
|
108
|
-
return _(instances)
|
|
109
|
-
.groupBy((i) => i.flavor.name)
|
|
110
|
-
.map((instances, flavorName) => ({
|
|
111
|
-
flavor: flavorName,
|
|
112
|
-
count: instances.length,
|
|
113
|
-
}))
|
|
114
|
-
.value();
|
|
115
|
-
}
|
package/src/commands/stop.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { undeploy as stopApplication } from '@clevercloud/client/esm/api/v2/application.js';
|
|
2
|
-
import { Logger } from '../logger.js';
|
|
3
|
-
import * as Application from '../models/application.js';
|
|
4
|
-
import { sendToApi } from '../models/send-to-api.js';
|
|
5
|
-
|
|
6
|
-
export async function stop(params) {
|
|
7
|
-
const { alias, app: appIdOrName } = params.options;
|
|
8
|
-
const { ownerId, appId } = await Application.resolveId(appIdOrName, alias);
|
|
9
|
-
|
|
10
|
-
await stopApplication({ id: ownerId, appId }).then(sendToApi);
|
|
11
|
-
Logger.printSuccess('Application successfully stopped!');
|
|
12
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { addTcpRedir, getTcpRedirs, removeTcpRedir } from '@clevercloud/client/esm/api/v2/application.js';
|
|
2
|
-
import { Logger } from '../logger.js';
|
|
3
|
-
import * as Application from '../models/application.js';
|
|
4
|
-
import * as Namespaces from '../models/namespaces.js';
|
|
5
|
-
import { sendToApi } from '../models/send-to-api.js';
|
|
6
|
-
|
|
7
|
-
export async function listNamespaces(params) {
|
|
8
|
-
const { alias, app: appIdOrName, format } = params.options;
|
|
9
|
-
const { ownerId } = await Application.resolveId(appIdOrName, alias);
|
|
10
|
-
|
|
11
|
-
const namespaces = await Namespaces.getNamespaces(ownerId);
|
|
12
|
-
|
|
13
|
-
namespaces.sort((a, b) => a.namespace.localeCompare(b.namespace));
|
|
14
|
-
|
|
15
|
-
switch (format) {
|
|
16
|
-
case 'json': {
|
|
17
|
-
Logger.printJson(namespaces);
|
|
18
|
-
break;
|
|
19
|
-
}
|
|
20
|
-
case 'human':
|
|
21
|
-
default: {
|
|
22
|
-
Logger.println('Available namespaces:');
|
|
23
|
-
namespaces.forEach(({ namespace }) => {
|
|
24
|
-
switch (namespace) {
|
|
25
|
-
case 'cleverapps':
|
|
26
|
-
Logger.println(`- ${namespace}: for redirections used with 'cleverapps.io' domain`);
|
|
27
|
-
break;
|
|
28
|
-
case 'default':
|
|
29
|
-
Logger.println(`- ${namespace}: for redirections used with custom domains`);
|
|
30
|
-
break;
|
|
31
|
-
default:
|
|
32
|
-
Logger.println(`- ${namespace}`);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export async function list(params) {
|
|
41
|
-
const { alias, app: appIdOrName, format } = params.options;
|
|
42
|
-
const { ownerId, appId } = await Application.resolveId(appIdOrName, alias);
|
|
43
|
-
|
|
44
|
-
const redirs = await getTcpRedirs({ id: ownerId, appId }).then(sendToApi);
|
|
45
|
-
|
|
46
|
-
switch (format) {
|
|
47
|
-
case 'json': {
|
|
48
|
-
Logger.printJson(redirs);
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
case 'human':
|
|
52
|
-
default: {
|
|
53
|
-
if (redirs.length === 0) {
|
|
54
|
-
Logger.println('No active TCP redirection for this application');
|
|
55
|
-
} else {
|
|
56
|
-
Logger.println('Enabled TCP redirections:');
|
|
57
|
-
for (const { namespace, port } of redirs) {
|
|
58
|
-
Logger.println(port + ' on ' + namespace);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export async function add(params) {
|
|
66
|
-
const { alias, app: appIdOrName, namespace } = params.options;
|
|
67
|
-
const { ownerId, appId } = await Application.resolveId(appIdOrName, alias);
|
|
68
|
-
const { port } = await addTcpRedir({ id: ownerId, appId }, { namespace }).then(sendToApi);
|
|
69
|
-
Logger.println('Successfully added tcp redirection on port: ' + port);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export async function remove(params) {
|
|
73
|
-
const [port] = params.args;
|
|
74
|
-
const { alias, app: appIdOrName, namespace } = params.options;
|
|
75
|
-
const { ownerId, appId } = await Application.resolveId(appIdOrName, alias);
|
|
76
|
-
|
|
77
|
-
await removeTcpRedir({ id: ownerId, appId, sourcePort: port, namespace }).then(sendToApi);
|
|
78
|
-
|
|
79
|
-
Logger.println('Successfully removed tcp redirection.');
|
|
80
|
-
}
|
package/src/commands/tokens.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import dedent from 'dedent';
|
|
2
|
-
import { createApiToken, deleteApiToken, listApiTokens } from '../clever-client/auth-bridge.js';
|
|
3
|
-
import { formatDate } from '../lib/format-date.js';
|
|
4
|
-
import { promptSecret } from '../lib/prompts.js';
|
|
5
|
-
import { styleText } from '../lib/style-text.js';
|
|
6
|
-
import { Logger } from '../logger.js';
|
|
7
|
-
import { conf } from '../models/configuration.js';
|
|
8
|
-
import { sendToAuthBridge } from '../models/send-to-api.js';
|
|
9
|
-
import { getCurrent as getCurrentUser } from '../models/user.js';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Create a new API token
|
|
13
|
-
* @param {Object} params - Function parameters
|
|
14
|
-
* @param {[string]} params.args - Command line args
|
|
15
|
-
* @param {Object} params.options - Command line options
|
|
16
|
-
* @param {'json'|'human'} params.options.format - Output format
|
|
17
|
-
* @param {number} params.options.expiration - Expiration date as timestamp
|
|
18
|
-
*/
|
|
19
|
-
export async function create(params) {
|
|
20
|
-
const [apiTokenName] = params.args;
|
|
21
|
-
const { expiration, format } = params.options;
|
|
22
|
-
const user = await getCurrentUser();
|
|
23
|
-
|
|
24
|
-
if (!user.hasPassword) {
|
|
25
|
-
const apiTokenListHref = new URL('/users/me/api-tokens', conf.CONSOLE_URL).href;
|
|
26
|
-
throw new Error(dedent`
|
|
27
|
-
${styleText('yellow', '!')} Your Clever Cloud account is linked via GitHub and has no password. Setting one is required to create API tokens.
|
|
28
|
-
${styleText('blue', '→')} To do so, go to the following URL: ${styleText('blue', apiTokenListHref)}
|
|
29
|
-
`);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Expire in 1 year
|
|
33
|
-
const dateObject = new Date();
|
|
34
|
-
dateObject.setFullYear(dateObject.getFullYear() + 1);
|
|
35
|
-
const maxExpirationDate = dateObject;
|
|
36
|
-
|
|
37
|
-
let expirationDate;
|
|
38
|
-
if (expiration != null) {
|
|
39
|
-
if (expiration > maxExpirationDate.getTime()) {
|
|
40
|
-
throw new Error('You cannot set an expiration date greater than 1 year');
|
|
41
|
-
}
|
|
42
|
-
expirationDate = new Date(expiration);
|
|
43
|
-
} else {
|
|
44
|
-
expirationDate = maxExpirationDate;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const password = await promptSecret('Enter your password:');
|
|
48
|
-
|
|
49
|
-
let mfaCode;
|
|
50
|
-
if (user.preferredMFA === 'TOTP') {
|
|
51
|
-
mfaCode = await promptSecret('Enter your 2FA code:');
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const tokenData = {
|
|
55
|
-
email: user.email,
|
|
56
|
-
password,
|
|
57
|
-
mfaCode,
|
|
58
|
-
name: apiTokenName,
|
|
59
|
-
expirationDate: expirationDate.toISOString(),
|
|
60
|
-
};
|
|
61
|
-
const createdToken = await createApiToken(tokenData)
|
|
62
|
-
.then(sendToAuthBridge)
|
|
63
|
-
.catch((error) => {
|
|
64
|
-
const errorCode = error?.cause?.responseBody?.code;
|
|
65
|
-
if (errorCode === 'invalid-credential') {
|
|
66
|
-
throw new Error('Invalid credentials, check your password');
|
|
67
|
-
}
|
|
68
|
-
if (errorCode === 'invalid-mfa-code') {
|
|
69
|
-
throw new Error('Invalid credentials, check your 2FA code');
|
|
70
|
-
}
|
|
71
|
-
throw error;
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
switch (format) {
|
|
75
|
-
case 'json':
|
|
76
|
-
Logger.printJson(createdToken);
|
|
77
|
-
break;
|
|
78
|
-
case 'human':
|
|
79
|
-
default:
|
|
80
|
-
Logger.println(dedent`
|
|
81
|
-
${styleText('green', '✔')} API token successfully created! Store it securely, you won't able to print it again.
|
|
82
|
-
|
|
83
|
-
- API token ID : ${styleText('grey', createdToken.apiTokenId)}
|
|
84
|
-
- API token : ${styleText('grey', createdToken.apiToken)}
|
|
85
|
-
- Expiration : ${styleText('grey', formatDate(createdToken.expirationDate))}
|
|
86
|
-
|
|
87
|
-
Export this token and use it to make authenticated requests to the Clever Cloud API through the Auth Bridge:
|
|
88
|
-
|
|
89
|
-
export CC_API_TOKEN=${createdToken.apiToken}
|
|
90
|
-
curl -H "Authorization: Bearer $CC_API_TOKEN" ${conf.AUTH_BRIDGE_HOST}/v2/self
|
|
91
|
-
|
|
92
|
-
Then, to revoke this token, run:
|
|
93
|
-
clever tokens revoke ${createdToken.apiTokenId}
|
|
94
|
-
`);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Get information about an API token
|
|
100
|
-
* @param {Object} params - Function parameters
|
|
101
|
-
* @param {Object} params.options - Command line options
|
|
102
|
-
* @param {Object} params.options.format - Output format
|
|
103
|
-
* @returns {Promise<void>}
|
|
104
|
-
*/
|
|
105
|
-
export async function list(params) {
|
|
106
|
-
const { format } = params.options;
|
|
107
|
-
|
|
108
|
-
const tokens = await listApiTokens().then(sendToAuthBridge);
|
|
109
|
-
|
|
110
|
-
if (format === 'json') {
|
|
111
|
-
Logger.printJson(tokens);
|
|
112
|
-
} else {
|
|
113
|
-
if (tokens.length === 0) {
|
|
114
|
-
Logger.println(`ℹ️ No API token found, create one with ${styleText('blue', 'clever tokens create')} command`);
|
|
115
|
-
} else {
|
|
116
|
-
console.table(
|
|
117
|
-
tokens.map((token) => {
|
|
118
|
-
return {
|
|
119
|
-
'API token ID': token.apiTokenId,
|
|
120
|
-
Name: token.name,
|
|
121
|
-
'Creation IP address': token.ip,
|
|
122
|
-
Creation: formatDate(token.creationDate),
|
|
123
|
-
Expiration: formatDate(token.expirationDate),
|
|
124
|
-
State: token.state,
|
|
125
|
-
};
|
|
126
|
-
}),
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Revoke an API token
|
|
134
|
-
* @param {Object} params - Function parameters
|
|
135
|
-
* @param {string[]} params.args - Command line arguments, token ID to revoke is expected as first argument
|
|
136
|
-
* @returns {Promise<void>}
|
|
137
|
-
*/
|
|
138
|
-
export async function revoke(params) {
|
|
139
|
-
const [apiTokenId] = params.args;
|
|
140
|
-
|
|
141
|
-
await deleteApiToken(apiTokenId).then(sendToAuthBridge);
|
|
142
|
-
|
|
143
|
-
Logger.println(styleText('green', '✔'), 'API token successfully revoked!');
|
|
144
|
-
}
|
package/src/commands/unlink.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { styleText } from '../lib/style-text.js';
|
|
2
|
-
import { Logger } from '../logger.js';
|
|
3
|
-
import * as AppConfig from '../models/app_configuration.js';
|
|
4
|
-
import * as Application from '../models/application.js';
|
|
5
|
-
|
|
6
|
-
export async function unlink(params) {
|
|
7
|
-
const [alias] = params.args;
|
|
8
|
-
const app = await AppConfig.getAppDetails({ alias });
|
|
9
|
-
|
|
10
|
-
await Application.unlinkRepo(app.alias);
|
|
11
|
-
Logger.printSuccess(
|
|
12
|
-
`Application ${styleText('green', app.appId)} has been successfully unlinked from local alias ${styleText('green', app.alias)}!`,
|
|
13
|
-
);
|
|
14
|
-
}
|
package/src/commands/version.js
DELETED
package/src/commands/webhooks.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { createWebhook, deleteWebhook, getWebhooks } from '@clevercloud/client/esm/api/v2/notification.js';
|
|
2
|
-
import { styleText } from '../lib/style-text.js';
|
|
3
|
-
import { Logger } from '../logger.js';
|
|
4
|
-
import { getOrgaIdOrUserId, getOwnerAndApp } from '../models/notification.js';
|
|
5
|
-
import { sendToApi } from '../models/send-to-api.js';
|
|
6
|
-
|
|
7
|
-
export async function list(params) {
|
|
8
|
-
const { org, 'list-all': listAll, format } = params.options;
|
|
9
|
-
|
|
10
|
-
// TODO: fix alias option
|
|
11
|
-
const { ownerId, appId } = await getOwnerAndApp(null, org, !listAll);
|
|
12
|
-
const hooks = await getWebhooks({ ownerId }).then(sendToApi);
|
|
13
|
-
|
|
14
|
-
const formattedHooks = hooks
|
|
15
|
-
.filter((hook) => {
|
|
16
|
-
const emptyScope = !hook.scope || hook.scope.length === 0;
|
|
17
|
-
return !appId || emptyScope || hook.scope.includes(appId);
|
|
18
|
-
})
|
|
19
|
-
.map((hook) => ({
|
|
20
|
-
id: hook.id,
|
|
21
|
-
name: hook.name,
|
|
22
|
-
ownerId: hook.ownerId,
|
|
23
|
-
services: hook.scope ?? [hook.ownerId],
|
|
24
|
-
events: hook.events ?? ['ALL'],
|
|
25
|
-
urls: hook.urls,
|
|
26
|
-
}));
|
|
27
|
-
|
|
28
|
-
switch (format) {
|
|
29
|
-
case 'json': {
|
|
30
|
-
Logger.printJson(formattedHooks);
|
|
31
|
-
break;
|
|
32
|
-
}
|
|
33
|
-
case 'human':
|
|
34
|
-
default: {
|
|
35
|
-
formattedHooks.forEach((hook) => {
|
|
36
|
-
Logger.println(hook.name ? styleText('bold', hook.name) : hook.id);
|
|
37
|
-
Logger.println(` id: ${hook.id}`);
|
|
38
|
-
Logger.println(` services: ${hook.services.join(', ')}`);
|
|
39
|
-
Logger.println(` events: ${hook.events.join(', ')}`);
|
|
40
|
-
Logger.println(' hooks:');
|
|
41
|
-
hook.urls.forEach((url) => Logger.println(` ${url.url} (${url.format})`));
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export async function add(params) {
|
|
48
|
-
const { org, format, event: events, service } = params.options;
|
|
49
|
-
const [name, hookUrl] = params.args;
|
|
50
|
-
|
|
51
|
-
// TODO: fix alias option
|
|
52
|
-
const { ownerId, appId } = await getOwnerAndApp(null, org, !org && !service);
|
|
53
|
-
|
|
54
|
-
const body = {
|
|
55
|
-
name,
|
|
56
|
-
urls: [{ format, url: hookUrl }],
|
|
57
|
-
scope: appId != null && service == null ? [appId] : service,
|
|
58
|
-
events,
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
await createWebhook({ ownerId }, body).then(sendToApi);
|
|
62
|
-
|
|
63
|
-
Logger.println('The webhook has been added');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export async function remove(params) {
|
|
67
|
-
const { org } = params.options;
|
|
68
|
-
const [notificationId] = params.args;
|
|
69
|
-
|
|
70
|
-
const ownerId = await getOrgaIdOrUserId(org);
|
|
71
|
-
await deleteWebhook({ ownerId, id: notificationId }).then(sendToApi);
|
|
72
|
-
|
|
73
|
-
Logger.println('The notification has been successfully removed');
|
|
74
|
-
}
|