clever-tools 4.0.2 → 4.2.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 +25 -74
- package/package.json +2 -2
- package/src/commands/accesslogs.js +1 -1
- package/src/commands/addon.js +119 -146
- package/src/commands/diag.js +33 -4
- package/src/commands/domain.js +67 -46
- package/src/commands/emails.js +1 -15
- package/src/commands/link.js +4 -4
- package/src/commands/ng.js +1 -1
- package/src/commands/ssh-keys.js +2 -13
- package/src/commands/status.js +5 -0
- package/src/commands/tcp-redirs.js +2 -31
- package/src/commands/tokens.js +1 -4
- package/src/experimental-features.js +5 -5
- package/src/lib/format-date.js +3 -0
- package/src/logger.js +10 -0
- package/src/models/app_configuration.js +10 -6
- package/src/models/emails.js +16 -0
- package/src/models/log-v4.js +3 -2
- package/src/models/ng-resources.js +16 -28
- package/src/models/ng.js +14 -15
- package/src/models/ssh-keys.js +10 -0
- package/src/parsers.js +3 -2
package/src/models/ng.js
CHANGED
|
@@ -17,9 +17,13 @@ import * as User from './user.js';
|
|
|
17
17
|
export const POLLING_TIMEOUT_MS = 30_000;
|
|
18
18
|
export const POLLING_INTERVAL_MS = 1000;
|
|
19
19
|
export const DOMAIN = 'cc-ng.cloud';
|
|
20
|
-
const
|
|
20
|
+
export const NG_MEMBER_PREFIXES = {
|
|
21
21
|
app_: 'APPLICATION',
|
|
22
|
-
|
|
22
|
+
elasticsearch_: 'ADDON',
|
|
23
|
+
mongodb_: 'ADDON',
|
|
24
|
+
mysql_: 'ADDON',
|
|
25
|
+
postgresql_: 'ADDON',
|
|
26
|
+
redis_: 'ADDON',
|
|
23
27
|
external_: 'EXTERNAL',
|
|
24
28
|
};
|
|
25
29
|
|
|
@@ -37,7 +41,7 @@ export async function create(label, description, tags, membersIds, orgaIdOrName)
|
|
|
37
41
|
const ownerId = await getOwnerIdFromOrgaIdOrName(orgaIdOrName);
|
|
38
42
|
|
|
39
43
|
if (membersIds?.length > 0) {
|
|
40
|
-
|
|
44
|
+
checkMembersToLink(membersIds);
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
const members = constructMembers(id, membersIds || []);
|
|
@@ -72,11 +76,11 @@ export async function destroy(ngIdOrLabel, orgaIdOrName) {
|
|
|
72
76
|
}
|
|
73
77
|
|
|
74
78
|
/**
|
|
75
|
-
* Get the
|
|
79
|
+
* Get the WireGuard configuration of a Network Group peer
|
|
76
80
|
* @param {object} peerIdOrLabel The Peer ID or Label
|
|
77
81
|
* @param {object} ngIdOrLabel The Network Group ID or Label
|
|
78
82
|
* @param {object} orgaIdOrName The owner ID or name
|
|
79
|
-
* @returns {Promise<Object>} The Peer
|
|
83
|
+
* @returns {Promise<Object>} The Peer WireGuard configuration
|
|
80
84
|
* @throws {Error} If the Peer is not found
|
|
81
85
|
* @throws {Error} If the Network Group is not found
|
|
82
86
|
* @throws {Error} If the Peer is not in the Network Group
|
|
@@ -116,7 +120,7 @@ export async function getPeerConfig(peerIdOrLabel, ngIdOrLabel, orgaIdOrName) {
|
|
|
116
120
|
}
|
|
117
121
|
|
|
118
122
|
/**
|
|
119
|
-
* Get a Network
|
|
123
|
+
* Get a Network Group from an owner with members and peers
|
|
120
124
|
* @param {string} networkGroupId The Network Group ID
|
|
121
125
|
* @param {string} orgaIdOrName The owner ID or name
|
|
122
126
|
* @returns {Promise<Array<Object>>} The Network Groups
|
|
@@ -187,7 +191,7 @@ export async function searchNgOrResource(idOrLabel, orgaIdOrName, type = 'all',
|
|
|
187
191
|
|
|
188
192
|
if (filtered.length > 1 && type !== 'all') {
|
|
189
193
|
throw new Error(`Multiple resources found for ${styleText('red', query)}, use ID instead:
|
|
190
|
-
${filtered.map((f) => ` • ${f.id} ${styleText('grey', `(${f.label} - ${f.type})`)}`).join('\n')}`);
|
|
194
|
+
${filtered.map((f) => ` • ${f.id} ${styleText('grey', `(${f.domainName || f.label} - ${f.type})`)}`).join('\n')}`);
|
|
191
195
|
}
|
|
192
196
|
|
|
193
197
|
// Deduplicate results
|
|
@@ -203,14 +207,9 @@ ${filtered.map((f) => ` • ${f.id} ${styleText('grey', `(${f.label} - ${f.type}
|
|
|
203
207
|
export function constructMembers(ngId, membersIds) {
|
|
204
208
|
return membersIds.map((id) => {
|
|
205
209
|
const domainName = `${id}.m.${ngId}.${DOMAIN}`;
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
return {
|
|
209
|
-
id,
|
|
210
|
-
domainName,
|
|
211
|
-
// Get kind from prefix match in id (app_*, addon_*, external_*) or default to 'APPLICATION'
|
|
212
|
-
kind: prefixToType[Object.keys(prefixToType).find((p) => id.startsWith(p))] ?? TYPE_PREFIXES.app_,
|
|
213
|
-
};
|
|
210
|
+
const prefix = Object.keys(NG_MEMBER_PREFIXES).find((p) => id.startsWith(p));
|
|
211
|
+
const kind = NG_MEMBER_PREFIXES[prefix];
|
|
212
|
+
return { id, domainName, kind };
|
|
214
213
|
});
|
|
215
214
|
}
|
|
216
215
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { todo_getSshKeys as getSshKeys } from '@clevercloud/client/esm/api/v2/user.js';
|
|
2
|
+
import { sendToApi } from './send-to-api.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @return {Promise<Array<{ name: string, key: string, fingerprint: string }>>}
|
|
6
|
+
*/
|
|
7
|
+
export async function getUserSshKeys() {
|
|
8
|
+
const rawKeys = await getSshKeys().then(sendToApi);
|
|
9
|
+
return rawKeys.sort((a, b) => a.name.localeCompare(b.name));
|
|
10
|
+
}
|
package/src/parsers.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import cliparse from 'cliparse';
|
|
2
2
|
import ISO8601 from 'iso8601-duration';
|
|
3
3
|
import * as Application from './models/application.js';
|
|
4
|
+
import { NG_MEMBER_PREFIXES } from './models/ng.js';
|
|
4
5
|
|
|
5
6
|
const addonOptionsRegex = /^[\w-]+=.+$/;
|
|
6
7
|
|
|
@@ -225,12 +226,12 @@ function parseSimpleDuration(durationStr) {
|
|
|
225
226
|
}
|
|
226
227
|
}
|
|
227
228
|
|
|
228
|
-
// Network
|
|
229
|
+
// Network Groups parsers
|
|
229
230
|
export function ngResourceType(string) {
|
|
230
231
|
if (string.startsWith('ng_')) {
|
|
231
232
|
return cliparse.parsers.success({ ngId: string });
|
|
232
233
|
}
|
|
233
|
-
if (
|
|
234
|
+
if (Object.keys(NG_MEMBER_PREFIXES).some((prefix) => string.startsWith(prefix))) {
|
|
234
235
|
return cliparse.parsers.success({ memberId: string });
|
|
235
236
|
}
|
|
236
237
|
return cliparse.parsers.success({ ngResourceLabel: string });
|