clever-tools 3.8.2 → 3.9.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 +177 -426
- package/package.json +11 -5
- package/src/command-options.js +4 -10
- package/src/command-promise-handler.js +5 -7
- package/src/commands/accesslogs.js +9 -13
- package/src/commands/activity.js +10 -14
- package/src/commands/addon.js +82 -36
- package/src/commands/applications.js +9 -16
- package/src/commands/cancel-deploy.js +5 -9
- package/src/commands/config.js +7 -11
- package/src/commands/console.js +5 -9
- package/src/commands/create.js +5 -9
- package/src/commands/curl.js +7 -11
- package/src/commands/database.js +13 -16
- package/src/commands/delete.js +4 -8
- package/src/commands/deploy.js +10 -14
- package/src/commands/diag.js +9 -11
- package/src/commands/domain.js +348 -17
- package/src/commands/drain.js +10 -20
- package/src/commands/env.js +13 -17
- package/src/commands/link.js +3 -7
- package/src/commands/login.js +13 -15
- package/src/commands/logout.js +3 -7
- package/src/commands/logs.js +9 -13
- package/src/commands/makeDefault.js +3 -7
- package/src/commands/notify-email.js +9 -19
- package/src/commands/open.js +5 -9
- package/src/commands/profile.js +21 -12
- package/src/commands/published-config.js +11 -15
- package/src/commands/restart.js +7 -11
- package/src/commands/scale.js +3 -7
- package/src/commands/service.js +8 -18
- package/src/commands/ssh.js +4 -8
- package/src/commands/status.js +7 -11
- package/src/commands/stop.js +5 -9
- package/src/commands/tcp-redirs.js +11 -15
- package/src/commands/unlink.js +4 -8
- package/src/commands/version.js +4 -6
- package/src/commands/webhooks.js +8 -16
- package/src/format-table.js +4 -8
- package/src/initial-setup.js +49 -0
- package/src/load-package-json.cjs +5 -0
- package/src/logger.js +5 -8
- package/src/models/activity.js +3 -7
- package/src/models/addon.js +52 -54
- package/src/models/app_configuration.js +18 -31
- package/src/models/application.js +37 -61
- package/src/models/application_configuration.js +11 -15
- package/src/models/configuration.js +11 -15
- package/src/models/deployments.js +6 -10
- package/src/models/domain.js +6 -10
- package/src/models/drain.js +5 -13
- package/src/models/exit-strategy-option.js +4 -8
- package/src/models/fs-utils.js +3 -7
- package/src/models/git.js +19 -34
- package/src/models/ids-resolver.js +6 -12
- package/src/models/interact.js +2 -6
- package/src/models/isomorphic-http-with-agent.js +3 -9
- package/src/models/json-array.js +1 -3
- package/src/models/log-v4.js +10 -12
- package/src/models/log.js +11 -15
- package/src/models/namespaces.js +7 -13
- package/src/models/node-dns-resolver.js +43 -0
- package/src/models/notification.js +8 -17
- package/src/models/organisation.js +4 -10
- package/src/models/send-to-api.js +17 -13
- package/src/models/user.js +16 -9
- package/src/models/utils.js +2 -6
- package/src/models/variables.js +4 -10
- package/src/parsers.js +21 -71
- package/src/commands/networkgroups/commands.js +0 -7
- package/src/commands/networkgroups/index.js +0 -67
- package/src/commands/networkgroups/members.js +0 -80
- package/src/commands/networkgroups/peers.js +0 -83
- package/src/models/format-ng-table.js +0 -115
- package/src/models/format-string.js +0 -44
- package/src/models/networkgroup.js +0 -64
- package/src/models/wireguard-conf.js +0 -95
- package/src/models/wireguard.js +0 -75
package/src/format-table.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import table from 'text-table';
|
|
3
|
+
import stringLength from 'string-length';
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
const table = require('text-table');
|
|
5
|
-
const stringLength = require('string-length');
|
|
6
|
-
|
|
7
|
-
function formatTable (columnWidth = []) {
|
|
5
|
+
export function formatTable (columnWidth = []) {
|
|
8
6
|
|
|
9
7
|
const fixedWidthPlaceholder = columnWidth.map((item) => {
|
|
10
8
|
if (typeof item === 'number') {
|
|
@@ -20,5 +18,3 @@ function formatTable (columnWidth = []) {
|
|
|
20
18
|
.join('\n');
|
|
21
19
|
};
|
|
22
20
|
}
|
|
23
|
-
|
|
24
|
-
module.exports = formatTable;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import colors from 'colors/safe.js';
|
|
2
|
+
import { getPackageJson } from './load-package-json.cjs';
|
|
3
|
+
import updateNotifierModule from 'update-notifier';
|
|
4
|
+
|
|
5
|
+
function hasParam (param, paramValue) {
|
|
6
|
+
const index = process.argv.indexOf(param);
|
|
7
|
+
if (index === -1) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
if (paramValue != null) {
|
|
11
|
+
return process.argv[index + 1] === paramValue;
|
|
12
|
+
}
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// These need to be set before Logger and other stuffs
|
|
17
|
+
if (hasParam('-v') || hasParam('--verbose')) {
|
|
18
|
+
process.env.CLEVER_VERBOSE = '1';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// These need to be set before Logger and other stuffs
|
|
22
|
+
// Don't log anything in autocomplete mode
|
|
23
|
+
if (hasParam('--autocomplete-index')) {
|
|
24
|
+
process.env.CLEVER_QUIET = '1';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// These need to be set before other stuffs
|
|
28
|
+
const colorExplicitFalse = hasParam('--no-color') || hasParam('--color', 'false');
|
|
29
|
+
const colorExplicitTrue = hasParam('--color', 'true');
|
|
30
|
+
if (colorExplicitFalse || (!process.stdout.isTTY && !colorExplicitTrue)) {
|
|
31
|
+
colors.disable();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// These need to be set before Logger and other stuffs
|
|
35
|
+
const pkg = getPackageJson();
|
|
36
|
+
const isRunThroughPackagedBinary = process.pkg != null;
|
|
37
|
+
const updateNotifierExplicitFalse = hasParam('--no-update-notifier') || hasParam('--update-notifier', 'false');
|
|
38
|
+
if (!updateNotifierExplicitFalse && !isRunThroughPackagedBinary) {
|
|
39
|
+
updateNotifierModule({
|
|
40
|
+
pkg,
|
|
41
|
+
tagsUrl: 'https://api.github.com/repos/CleverCloud/clever-tools/tags',
|
|
42
|
+
}).notify({
|
|
43
|
+
isGlobal: true,
|
|
44
|
+
getDetails () {
|
|
45
|
+
const docsUrl = 'https://github.com/CleverCloud/clever-tools/tree/master/docs#how-to-use-clever-tools';
|
|
46
|
+
return `\nPlease follow this link to update your clever-tools:\n${docsUrl}`;
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
package/src/logger.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const colors = require('colors/safe');
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import colors from 'colors/safe.js';
|
|
3
|
+
import { format } from 'node:util';
|
|
5
4
|
|
|
6
5
|
function getPrefix (severity) {
|
|
7
6
|
const prefix = `[${severity.toUpperCase()}] `;
|
|
@@ -29,10 +28,10 @@ function formatLines (prefixLength, lines) {
|
|
|
29
28
|
}
|
|
30
29
|
|
|
31
30
|
function consoleErrorWithoutColor (line) {
|
|
32
|
-
process.stderr.write(line + '\n');
|
|
31
|
+
process.stderr.write(format(line) + '\n');
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
const Logger = _(['debug', 'info', 'warn', 'error'])
|
|
34
|
+
export const Logger = _(['debug', 'info', 'warn', 'error'])
|
|
36
35
|
.map((severity) => {
|
|
37
36
|
if (process.env.CLEVER_QUIET || (!process.env.CLEVER_VERBOSE && (severity === 'debug' || severity === 'info'))) {
|
|
38
37
|
return [severity, _.noop];
|
|
@@ -65,5 +64,3 @@ Logger.printErrorLine = consoleErrorWithoutColor;
|
|
|
65
64
|
|
|
66
65
|
// Only exported for testing, shouldn't be used directly
|
|
67
66
|
Logger.processApiError = processApiError;
|
|
68
|
-
|
|
69
|
-
module.exports = Logger;
|
package/src/models/activity.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import * as application from '@clevercloud/client/esm/api/v2/application.js';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { sendToApi } from './send-to-api.js';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function list (ownerId, appId, showAll) {
|
|
5
|
+
export function list (ownerId, appId, showAll) {
|
|
8
6
|
const limit = showAll ? null : 10;
|
|
9
7
|
return application.getAllDeployments({ id: ownerId, appId, limit }).then(sendToApi);
|
|
10
8
|
};
|
|
11
|
-
|
|
12
|
-
module.exports = { list };
|
package/src/models/addon.js
CHANGED
|
@@ -1,28 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const Interact = require('./interact.js');
|
|
17
|
-
const Logger = require('../logger.js');
|
|
18
|
-
const { sendToApi } = require('../models/send-to-api.js');
|
|
19
|
-
const { resolveOwnerId } = require('./ids-resolver.js');
|
|
20
|
-
|
|
21
|
-
function listProviders () {
|
|
1
|
+
import * as application from '@clevercloud/client/esm/api/v2/application.js';
|
|
2
|
+
import cliparse from 'cliparse';
|
|
3
|
+
|
|
4
|
+
import { get as getAddon, getAll as getAllAddons, getAllEnvVars, remove as removeAddon, create as createAddon, update as updateAddon } from '@clevercloud/client/esm/api/v2/addon.js';
|
|
5
|
+
import { getAllAddonProviders } from '@clevercloud/client/esm/api/v2/product.js';
|
|
6
|
+
import { getSummary } from '@clevercloud/client/esm/api/v2/user.js';
|
|
7
|
+
import { getAddonProvider } from '@clevercloud/client/esm/api/v4/addon-providers.js';
|
|
8
|
+
|
|
9
|
+
import * as Interact from './interact.js';
|
|
10
|
+
import { Logger } from '../logger.js';
|
|
11
|
+
import { sendToApi } from '../models/send-to-api.js';
|
|
12
|
+
import { resolveOwnerId } from './ids-resolver.js';
|
|
13
|
+
|
|
14
|
+
export function listProviders () {
|
|
22
15
|
return getAllAddonProviders({}).then(sendToApi);
|
|
23
16
|
}
|
|
24
17
|
|
|
25
|
-
async function getProvider (providerName) {
|
|
18
|
+
export async function getProvider (providerName) {
|
|
26
19
|
const providers = await listProviders();
|
|
27
20
|
const provider = providers.find((p) => p.id === providerName);
|
|
28
21
|
if (provider == null) {
|
|
@@ -31,7 +24,7 @@ async function getProvider (providerName) {
|
|
|
31
24
|
return provider;
|
|
32
25
|
}
|
|
33
26
|
|
|
34
|
-
function getProviderInfos (providerName) {
|
|
27
|
+
export function getProviderInfos (providerName) {
|
|
35
28
|
return getAddonProvider({ providerId: providerName }).then(sendToApi)
|
|
36
29
|
.catch(() => {
|
|
37
30
|
// An error can occur because the add-on api doesn't implement this endpoint yet
|
|
@@ -41,7 +34,7 @@ function getProviderInfos (providerName) {
|
|
|
41
34
|
});
|
|
42
35
|
}
|
|
43
36
|
|
|
44
|
-
async function list (ownerId, appId, showAll) {
|
|
37
|
+
export async function list (ownerId, appId, showAll) {
|
|
45
38
|
const allAddons = await getAllAddons({ id: ownerId }).then(sendToApi);
|
|
46
39
|
|
|
47
40
|
if (appId == null) {
|
|
@@ -133,7 +126,7 @@ function validateAddonVersionAndOptions (region, version, addonOptions, provider
|
|
|
133
126
|
}
|
|
134
127
|
}
|
|
135
128
|
|
|
136
|
-
async function create ({ ownerId, name, providerName, planName, region, skipConfirmation, version, addonOptions }) {
|
|
129
|
+
export async function create ({ ownerId, name, providerName, planName, region, skipConfirmation, version, addonOptions }) {
|
|
137
130
|
|
|
138
131
|
// TODO: We should be able to use it without {}
|
|
139
132
|
const provider = await getProvider(providerName);
|
|
@@ -168,7 +161,10 @@ async function create ({ ownerId, name, providerName, planName, region, skipConf
|
|
|
168
161
|
options: createOptions,
|
|
169
162
|
};
|
|
170
163
|
|
|
171
|
-
|
|
164
|
+
const createdAddon = await createAddon({ id: ownerId }, addonToCreate).then(sendToApi);
|
|
165
|
+
createdAddon.env = await getAllEnvVars({ id: ownerId, addonId: createdAddon.id }).then(sendToApi);
|
|
166
|
+
|
|
167
|
+
return createdAddon;
|
|
172
168
|
}
|
|
173
169
|
|
|
174
170
|
async function getByName (ownerId, addonNameOrRealId) {
|
|
@@ -193,17 +189,17 @@ async function getId (ownerId, addon) {
|
|
|
193
189
|
return addonDetails.id;
|
|
194
190
|
}
|
|
195
191
|
|
|
196
|
-
async function link (ownerId, appId, addon) {
|
|
192
|
+
export async function link (ownerId, appId, addon) {
|
|
197
193
|
const addonId = await getId(ownerId, addon);
|
|
198
194
|
return application.linkAddon({ id: ownerId, appId }, JSON.stringify(addonId)).then(sendToApi);
|
|
199
195
|
}
|
|
200
196
|
|
|
201
|
-
async function unlink (ownerId, appId, addon) {
|
|
197
|
+
export async function unlink (ownerId, appId, addon) {
|
|
202
198
|
const addonId = await getId(ownerId, addon);
|
|
203
199
|
return application.unlinkAddon({ id: ownerId, appId, addonId }).then(sendToApi);
|
|
204
200
|
}
|
|
205
201
|
|
|
206
|
-
async function deleteAddon (ownerId, addonIdOrName, skipConfirmation) {
|
|
202
|
+
export async function deleteAddon (ownerId, addonIdOrName, skipConfirmation) {
|
|
207
203
|
const addonId = await getId(ownerId, addonIdOrName);
|
|
208
204
|
|
|
209
205
|
if (!skipConfirmation) {
|
|
@@ -213,21 +209,21 @@ async function deleteAddon (ownerId, addonIdOrName, skipConfirmation) {
|
|
|
213
209
|
return removeAddon({ id: ownerId, addonId }).then(sendToApi);
|
|
214
210
|
}
|
|
215
211
|
|
|
216
|
-
async function rename (ownerId, addon, name) {
|
|
212
|
+
export async function rename (ownerId, addon, name) {
|
|
217
213
|
const addonId = await getId(ownerId, addon);
|
|
218
214
|
return updateAddon({ id: ownerId, addonId }, { name }).then(sendToApi);
|
|
219
215
|
}
|
|
220
216
|
|
|
221
|
-
function completeRegion () {
|
|
222
|
-
return autocomplete.words(['par', 'mtl']);
|
|
217
|
+
export function completeRegion () {
|
|
218
|
+
return cliparse.autocomplete.words(['par', 'mtl']);
|
|
223
219
|
}
|
|
224
220
|
|
|
225
221
|
// TODO: We need to fix this
|
|
226
|
-
function completePlan () {
|
|
227
|
-
return autocomplete.words(['dev', 's', 'm', 'l', 'xl', 'xxl']);
|
|
222
|
+
export function completePlan () {
|
|
223
|
+
return cliparse.autocomplete.words(['dev', 's', 'm', 'l', 'xl', 'xxl']);
|
|
228
224
|
}
|
|
229
225
|
|
|
230
|
-
async function findById (addonId) {
|
|
226
|
+
export async function findById (addonId) {
|
|
231
227
|
const { user, organisations } = await getSummary({}).then(sendToApi);
|
|
232
228
|
for (const orga of [user, ...organisations]) {
|
|
233
229
|
for (const simpleAddon of orga.addons) {
|
|
@@ -243,7 +239,23 @@ async function findById (addonId) {
|
|
|
243
239
|
throw new Error(`Could not find add-on with ID: ${addonId}`);
|
|
244
240
|
}
|
|
245
241
|
|
|
246
|
-
async function
|
|
242
|
+
export async function findByName (addonName) {
|
|
243
|
+
const { user, organisations } = await getSummary({}).then(sendToApi);
|
|
244
|
+
for (const orga of [user, ...organisations]) {
|
|
245
|
+
for (const simpleAddon of orga.addons) {
|
|
246
|
+
if (simpleAddon.name === addonName) {
|
|
247
|
+
const addon = await getAddon({ id: orga.id, addonId: simpleAddon.id }).then(sendToApi);
|
|
248
|
+
return {
|
|
249
|
+
...addon,
|
|
250
|
+
orgaId: orga.id,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
throw new Error(`Could not find add-on with name ${addonName}`);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export async function findOwnerId (org, addonId) {
|
|
247
259
|
|
|
248
260
|
if (org != null && org.orga_id != null) {
|
|
249
261
|
return org.orga_id;
|
|
@@ -257,7 +269,7 @@ async function findOwnerId (org, addonId) {
|
|
|
257
269
|
throw new Error(`Add-on ${addonId} does not exist`);
|
|
258
270
|
}
|
|
259
271
|
|
|
260
|
-
function parseAddonOptions (options) {
|
|
272
|
+
export function parseAddonOptions (options) {
|
|
261
273
|
if (options == null) {
|
|
262
274
|
return {};
|
|
263
275
|
}
|
|
@@ -275,6 +287,9 @@ function parseAddonOptions (options) {
|
|
|
275
287
|
else if (value === 'false' || value === 'disabled') {
|
|
276
288
|
formattedValue = 'false';
|
|
277
289
|
}
|
|
290
|
+
else if (typeof key === 'string') {
|
|
291
|
+
formattedValue = value;
|
|
292
|
+
}
|
|
278
293
|
else {
|
|
279
294
|
throw new Error(`Can't parse option value: ${value}. Accepted values are: enabled, disabled, true, false`);
|
|
280
295
|
}
|
|
@@ -297,20 +312,3 @@ function getPlan (planName, plans) {
|
|
|
297
312
|
}
|
|
298
313
|
return plan;
|
|
299
314
|
}
|
|
300
|
-
|
|
301
|
-
module.exports = {
|
|
302
|
-
completePlan,
|
|
303
|
-
completeRegion,
|
|
304
|
-
create,
|
|
305
|
-
delete: deleteAddon,
|
|
306
|
-
findById,
|
|
307
|
-
findOwnerId,
|
|
308
|
-
getProvider,
|
|
309
|
-
getProviderInfos,
|
|
310
|
-
link,
|
|
311
|
-
list,
|
|
312
|
-
listProviders,
|
|
313
|
-
parseAddonOptions,
|
|
314
|
-
rename,
|
|
315
|
-
unlink,
|
|
316
|
-
};
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
import _ from 'lodash';
|
|
5
|
+
import slugify from 'slugify';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const Logger = require('../logger.js');
|
|
10
|
-
const User = require('./user.js');
|
|
11
|
-
const { conf } = require('./configuration.js');
|
|
7
|
+
import { Logger } from '../logger.js';
|
|
8
|
+
import * as User from './user.js';
|
|
9
|
+
import { conf } from './configuration.js';
|
|
12
10
|
|
|
13
11
|
// TODO: Maybe use fs-utils findPath()
|
|
14
|
-
async function loadApplicationConf (ignoreParentConfig = false, pathToFolder) {
|
|
12
|
+
export async function loadApplicationConf (ignoreParentConfig = false, pathToFolder) {
|
|
15
13
|
if (pathToFolder == null) {
|
|
16
14
|
pathToFolder = path.dirname(conf.APP_CONFIGURATION_FILE);
|
|
17
15
|
}
|
|
@@ -31,7 +29,7 @@ async function loadApplicationConf (ignoreParentConfig = false, pathToFolder) {
|
|
|
31
29
|
}
|
|
32
30
|
};
|
|
33
31
|
|
|
34
|
-
async function addLinkedApplication (appData, alias, ignoreParentConfig) {
|
|
32
|
+
export async function addLinkedApplication (appData, alias, ignoreParentConfig) {
|
|
35
33
|
const currentConfig = await loadApplicationConf(ignoreParentConfig);
|
|
36
34
|
|
|
37
35
|
const appEntry = {
|
|
@@ -54,7 +52,7 @@ async function addLinkedApplication (appData, alias, ignoreParentConfig) {
|
|
|
54
52
|
return persistConfig(currentConfig);
|
|
55
53
|
};
|
|
56
54
|
|
|
57
|
-
async function removeLinkedApplication ({ appId, alias }) {
|
|
55
|
+
export async function removeLinkedApplication ({ appId, alias }) {
|
|
58
56
|
const currentConfig = await loadApplicationConf();
|
|
59
57
|
const newConfig = {
|
|
60
58
|
...currentConfig,
|
|
@@ -71,9 +69,9 @@ async function removeLinkedApplication ({ appId, alias }) {
|
|
|
71
69
|
return false;
|
|
72
70
|
};
|
|
73
71
|
|
|
74
|
-
function findApp (config, alias) {
|
|
72
|
+
export function findApp (config, alias) {
|
|
75
73
|
if (_.isEmpty(config.apps)) {
|
|
76
|
-
throw new Error('There
|
|
74
|
+
throw new Error('There is no linked or targeted application. Use `--app` option or `clever link` command.');
|
|
77
75
|
}
|
|
78
76
|
|
|
79
77
|
if (alias != null) {
|
|
@@ -90,7 +88,7 @@ function findApp (config, alias) {
|
|
|
90
88
|
return findDefaultApp(config);
|
|
91
89
|
}
|
|
92
90
|
|
|
93
|
-
function checkAlreadyLinked (apps, name, alias) {
|
|
91
|
+
export function checkAlreadyLinked (apps, name, alias) {
|
|
94
92
|
const appAliasExists = apps.some((app) => app.alias != null && app.alias === alias);
|
|
95
93
|
if (appAliasExists) {
|
|
96
94
|
throw new Error(`An application is already linked with the alias '${alias}'`);
|
|
@@ -104,7 +102,7 @@ function checkAlreadyLinked (apps, name, alias) {
|
|
|
104
102
|
|
|
105
103
|
function findDefaultApp (config) {
|
|
106
104
|
if (_.isEmpty(config.apps)) {
|
|
107
|
-
throw new Error('There
|
|
105
|
+
throw new Error('There is no linked or targeted application. Use `--app` option or `clever link` command.');
|
|
108
106
|
}
|
|
109
107
|
|
|
110
108
|
if (config.default != null) {
|
|
@@ -127,7 +125,7 @@ async function getAppDetailsForId (appId) {
|
|
|
127
125
|
const config = await loadApplicationConf();
|
|
128
126
|
|
|
129
127
|
if (_.isEmpty(config.apps)) {
|
|
130
|
-
throw new Error('There
|
|
128
|
+
throw new Error('There is no linked or targeted application. Use `--app` option or `clever link` command.');
|
|
131
129
|
}
|
|
132
130
|
|
|
133
131
|
const [appById, secondAppById] = _.filter(config.apps, { app_id: appId });
|
|
@@ -142,7 +140,7 @@ async function getAppDetailsForId (appId) {
|
|
|
142
140
|
return appById;
|
|
143
141
|
}
|
|
144
142
|
|
|
145
|
-
async function getAppDetails ({ alias }) {
|
|
143
|
+
export async function getAppDetails ({ alias }) {
|
|
146
144
|
const config = await loadApplicationConf();
|
|
147
145
|
const app = findApp(config, alias);
|
|
148
146
|
const ownerId = (app.org_id != null)
|
|
@@ -157,7 +155,7 @@ async function getAppDetails ({ alias }) {
|
|
|
157
155
|
};
|
|
158
156
|
};
|
|
159
157
|
|
|
160
|
-
async function getMostNaturalName (appId) {
|
|
158
|
+
export async function getMostNaturalName (appId) {
|
|
161
159
|
try {
|
|
162
160
|
const details = await getAppDetailsForId(appId);
|
|
163
161
|
return details.alias || details.name || appId;
|
|
@@ -172,20 +170,9 @@ function persistConfig (modifiedConfig) {
|
|
|
172
170
|
return fs.writeFile(conf.APP_CONFIGURATION_FILE, jsonContents);
|
|
173
171
|
};
|
|
174
172
|
|
|
175
|
-
async function setDefault (alias) {
|
|
173
|
+
export async function setDefault (alias) {
|
|
176
174
|
const config = await loadApplicationConf();
|
|
177
175
|
const app = findApp(config, alias);
|
|
178
176
|
const newConfig = { ...config, default: app.app_id };
|
|
179
177
|
return persistConfig(newConfig);
|
|
180
178
|
}
|
|
181
|
-
|
|
182
|
-
module.exports = {
|
|
183
|
-
loadApplicationConf,
|
|
184
|
-
addLinkedApplication,
|
|
185
|
-
removeLinkedApplication,
|
|
186
|
-
checkAlreadyLinked,
|
|
187
|
-
findApp,
|
|
188
|
-
getAppDetails,
|
|
189
|
-
getMostNaturalName,
|
|
190
|
-
setDefault,
|
|
191
|
-
};
|
|
@@ -1,36 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
function listAvailableTypes () {
|
|
20
|
-
return autocomplete.words(['docker', 'elixir', 'go', 'gradle', 'haskell', 'jar', 'maven', 'meteor', 'node', 'php', 'play1', 'play2', 'python', 'ruby', 'rust', 'sbt', 'static-apache', 'war']);
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import * as application from '@clevercloud/client/esm/api/v2/application.js';
|
|
3
|
+
import cliparse from 'cliparse';
|
|
4
|
+
import * as product from '@clevercloud/client/esm/api/v2/product.js';
|
|
5
|
+
import { getSummary } from '@clevercloud/client/esm/api/v2/user.js';
|
|
6
|
+
|
|
7
|
+
import * as AppConfiguration from './app_configuration.js';
|
|
8
|
+
import * as Interact from './interact.js';
|
|
9
|
+
import { Logger } from '../logger.js';
|
|
10
|
+
import * as Organisation from './organisation.js';
|
|
11
|
+
import * as User from './user.js';
|
|
12
|
+
|
|
13
|
+
import { sendToApi } from '../models/send-to-api.js';
|
|
14
|
+
import { resolveOwnerId } from './ids-resolver.js';
|
|
15
|
+
|
|
16
|
+
export function listAvailableTypes () {
|
|
17
|
+
return cliparse.autocomplete.words(['docker', 'elixir', 'go', 'gradle', 'haskell', 'jar', 'maven', 'meteor', 'node', 'php', 'play1', 'play2', 'python', 'ruby', 'rust', 'sbt', 'static-apache', 'war']);
|
|
21
18
|
};
|
|
22
19
|
|
|
23
|
-
const AVAILABLE_ZONES = ['par', 'grahds', 'rbx', 'rbxhds', 'scw', 'mtl', 'sgp', 'syd', 'wsw'];
|
|
20
|
+
export const AVAILABLE_ZONES = ['par', 'grahds', 'rbx', 'rbxhds', 'scw', 'mtl', 'sgp', 'syd', 'wsw'];
|
|
24
21
|
|
|
25
|
-
function listAvailableZones () {
|
|
26
|
-
return autocomplete.words(AVAILABLE_ZONES);
|
|
22
|
+
export function listAvailableZones () {
|
|
23
|
+
return cliparse.autocomplete.words(AVAILABLE_ZONES);
|
|
27
24
|
};
|
|
28
25
|
|
|
29
|
-
function listAvailableAliases () {
|
|
30
|
-
return AppConfiguration.loadApplicationConf().then(({ apps }) => autocomplete.words(_.map(apps, 'alias')));
|
|
26
|
+
export function listAvailableAliases () {
|
|
27
|
+
return AppConfiguration.loadApplicationConf().then(({ apps }) => cliparse.autocomplete.words(_.map(apps, 'alias')));
|
|
31
28
|
};
|
|
32
29
|
|
|
33
|
-
function listAvailableFlavors () {
|
|
30
|
+
export function listAvailableFlavors () {
|
|
34
31
|
return ['pico', 'nano', 'XS', 'S', 'M', 'L', 'XL', '2XL', '3XL'];
|
|
35
32
|
};
|
|
36
33
|
|
|
@@ -56,7 +53,7 @@ async function getInstanceType (type) {
|
|
|
56
53
|
return instanceVariant;
|
|
57
54
|
};
|
|
58
55
|
|
|
59
|
-
async function create (name, typeName, region, orgaIdOrName, github, isTask, envVars) {
|
|
56
|
+
export async function create (name, typeName, region, orgaIdOrName, github, isTask, envVars) {
|
|
60
57
|
Logger.debug('Create the application…');
|
|
61
58
|
|
|
62
59
|
const ownerId = (orgaIdOrName != null)
|
|
@@ -89,7 +86,7 @@ async function create (name, typeName, region, orgaIdOrName, github, isTask, env
|
|
|
89
86
|
return application.create({ id: ownerId }, newApp).then(sendToApi);
|
|
90
87
|
};
|
|
91
88
|
|
|
92
|
-
async function deleteApp (app, skipConfirmation) {
|
|
89
|
+
export async function deleteApp (app, skipConfirmation) {
|
|
93
90
|
Logger.debug('Deleting app: ' + app.name + ' (' + app.id + ')');
|
|
94
91
|
|
|
95
92
|
if (!skipConfirmation) {
|
|
@@ -103,7 +100,7 @@ async function deleteApp (app, skipConfirmation) {
|
|
|
103
100
|
return application.remove({ id: app.ownerId, appId: app.id }).then(sendToApi);
|
|
104
101
|
};
|
|
105
102
|
|
|
106
|
-
async function getAllApps (ownerId) {
|
|
103
|
+
export async function getAllApps (ownerId) {
|
|
107
104
|
|
|
108
105
|
const summary = await getSummary().then(sendToApi);
|
|
109
106
|
|
|
@@ -157,7 +154,7 @@ async function getByName (ownerId, name) {
|
|
|
157
154
|
return getApplicationByName(apps, name);
|
|
158
155
|
};
|
|
159
156
|
|
|
160
|
-
function get (ownerId, appId) {
|
|
157
|
+
export function get (ownerId, appId) {
|
|
161
158
|
Logger.debug(`Get information for the app: ${appId}`);
|
|
162
159
|
return application.get({ id: ownerId, appId }).then(sendToApi);
|
|
163
160
|
};
|
|
@@ -175,7 +172,7 @@ function getFromSelf (appId) {
|
|
|
175
172
|
* @param {string} alias
|
|
176
173
|
* @return {Promise<{appId: string, ownerId: string}>}
|
|
177
174
|
*/
|
|
178
|
-
async function resolveId (appIdOrName, alias) {
|
|
175
|
+
export async function resolveId (appIdOrName, alias) {
|
|
179
176
|
if (appIdOrName != null && alias != null) {
|
|
180
177
|
throw new Error('Only one of the `--app` or `--alias` options can be set at a time');
|
|
181
178
|
}
|
|
@@ -183,7 +180,7 @@ async function resolveId (appIdOrName, alias) {
|
|
|
183
180
|
// -- resolve by linked app
|
|
184
181
|
|
|
185
182
|
if (appIdOrName == null) {
|
|
186
|
-
const appDetails = await
|
|
183
|
+
const appDetails = await AppConfiguration.getAppDetails({ alias });
|
|
187
184
|
return { appId: appDetails.appId, ownerId: appDetails.ownerId };
|
|
188
185
|
}
|
|
189
186
|
|
|
@@ -226,7 +223,7 @@ async function resolveId (appIdOrName, alias) {
|
|
|
226
223
|
throw new Error('Ambiguous application name, use the `--app` option with one of the IDs above');
|
|
227
224
|
}
|
|
228
225
|
|
|
229
|
-
async function linkRepo (app, orgaIdOrName, alias, ignoreParentConfig) {
|
|
226
|
+
export async function linkRepo (app, orgaIdOrName, alias, ignoreParentConfig) {
|
|
230
227
|
Logger.debug(`Linking current repository to the app: ${app.app_id || app.app_name}`);
|
|
231
228
|
|
|
232
229
|
const ownerId = (orgaIdOrName != null)
|
|
@@ -240,18 +237,18 @@ async function linkRepo (app, orgaIdOrName, alias, ignoreParentConfig) {
|
|
|
240
237
|
return AppConfiguration.addLinkedApplication(appData, alias, ignoreParentConfig);
|
|
241
238
|
};
|
|
242
239
|
|
|
243
|
-
function unlinkRepo (alias) {
|
|
240
|
+
export function unlinkRepo (alias) {
|
|
244
241
|
Logger.debug(`Unlinking current repository from the app: ${alias}`);
|
|
245
242
|
return AppConfiguration.removeLinkedApplication({ alias });
|
|
246
243
|
};
|
|
247
244
|
|
|
248
|
-
function redeploy (ownerId, appId, commit, withoutCache) {
|
|
245
|
+
export function redeploy (ownerId, appId, commit, withoutCache) {
|
|
249
246
|
Logger.debug(`Redeploying the app: ${appId}`);
|
|
250
247
|
const useCache = (withoutCache) ? 'no' : null;
|
|
251
248
|
return application.redeploy({ id: ownerId, appId, commit, useCache }).then(sendToApi);
|
|
252
249
|
};
|
|
253
250
|
|
|
254
|
-
function mergeScalabilityParameters (scalabilityParameters, instance) {
|
|
251
|
+
export function mergeScalabilityParameters (scalabilityParameters, instance) {
|
|
255
252
|
const flavors = listAvailableFlavors();
|
|
256
253
|
|
|
257
254
|
if (scalabilityParameters.minFlavor) {
|
|
@@ -283,7 +280,7 @@ function mergeScalabilityParameters (scalabilityParameters, instance) {
|
|
|
283
280
|
return instance;
|
|
284
281
|
};
|
|
285
282
|
|
|
286
|
-
async function setScalability (appId, ownerId, scalabilityParameters, buildFlavor) {
|
|
283
|
+
export async function setScalability (appId, ownerId, scalabilityParameters, buildFlavor) {
|
|
287
284
|
Logger.info('Scaling the app: ' + appId);
|
|
288
285
|
|
|
289
286
|
const app = await application.get({ id: ownerId, appId }).then(sendToApi);
|
|
@@ -307,7 +304,7 @@ async function setScalability (appId, ownerId, scalabilityParameters, buildFlavo
|
|
|
307
304
|
return application.update({ id: ownerId, appId }, newConfig).then(sendToApi);
|
|
308
305
|
};
|
|
309
306
|
|
|
310
|
-
async function listDependencies (ownerId, appId, showAll) {
|
|
307
|
+
export async function listDependencies (ownerId, appId, showAll) {
|
|
311
308
|
const applicationDeps = await application.getAllDependencies({ id: ownerId, appId }).then(sendToApi);
|
|
312
309
|
|
|
313
310
|
if (!showAll) {
|
|
@@ -323,33 +320,12 @@ async function listDependencies (ownerId, appId, showAll) {
|
|
|
323
320
|
});
|
|
324
321
|
}
|
|
325
322
|
|
|
326
|
-
async function link (ownerId, appId, dependency) {
|
|
323
|
+
export async function link (ownerId, appId, dependency) {
|
|
327
324
|
const dependencyId = await getId(ownerId, dependency);
|
|
328
325
|
return application.addDependency({ id: ownerId, appId, dependencyId }).then(sendToApi);
|
|
329
326
|
};
|
|
330
327
|
|
|
331
|
-
async function unlink (ownerId, appId, dependency) {
|
|
328
|
+
export async function unlink (ownerId, appId, dependency) {
|
|
332
329
|
const dependencyId = await getId(ownerId, dependency);
|
|
333
330
|
return application.removeDependency({ id: ownerId, appId, dependencyId }).then(sendToApi);
|
|
334
331
|
};
|
|
335
|
-
|
|
336
|
-
module.exports = {
|
|
337
|
-
resolveId,
|
|
338
|
-
create,
|
|
339
|
-
deleteApp,
|
|
340
|
-
get,
|
|
341
|
-
getAllApps,
|
|
342
|
-
link,
|
|
343
|
-
linkRepo,
|
|
344
|
-
listAvailableAliases,
|
|
345
|
-
listAvailableFlavors,
|
|
346
|
-
listAvailableTypes,
|
|
347
|
-
AVAILABLE_ZONES,
|
|
348
|
-
listAvailableZones,
|
|
349
|
-
listDependencies,
|
|
350
|
-
__mergeScalabilityParameters: mergeScalabilityParameters,
|
|
351
|
-
redeploy,
|
|
352
|
-
setScalability,
|
|
353
|
-
unlink,
|
|
354
|
-
unlinkRepo,
|
|
355
|
-
};
|