balena-cli 16.7.4 → 16.7.5
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/CHANGELOG.md +4 -0
- package/build/commands/app/create.d.ts +1 -7
- package/build/commands/app/create.js +1 -39
- package/build/commands/app/create.js.map +1 -1
- package/build/commands/block/create.d.ts +0 -1
- package/build/commands/block/create.js +1 -39
- package/build/commands/block/create.js.map +1 -1
- package/build/commands/fleet/create.d.ts +1 -7
- package/build/commands/fleet/create.js +1 -38
- package/build/commands/fleet/create.js.map +1 -1
- package/build/utils/application-create.d.ts +9 -0
- package/build/utils/application-create.js +31 -0
- package/build/utils/application-create.js.map +1 -0
- package/build/utils/patterns.d.ts +1 -0
- package/build/utils/patterns.js +17 -1
- package/build/utils/patterns.js.map +1 -1
- package/lib/commands/app/create.ts +5 -68
- package/lib/commands/block/create.ts +4 -58
- package/lib/commands/fleet/create.ts +5 -67
- package/lib/utils/application-create.ts +58 -0
- package/lib/utils/patterns.ts +18 -0
- package/npm-shrinkwrap.json +2 -2
- package/oclif.manifest.json +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ExpectedError } from '../errors';
|
|
2
|
+
import { getBalenaSdk } from './lazy';
|
|
3
|
+
|
|
4
|
+
export interface FlagsDef {
|
|
5
|
+
organization?: string;
|
|
6
|
+
type?: string; // application device type
|
|
7
|
+
help: void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface ArgsDef {
|
|
11
|
+
name: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function applicationCreateBase(
|
|
15
|
+
resource: 'fleet' | 'app' | 'block',
|
|
16
|
+
options: FlagsDef,
|
|
17
|
+
params: ArgsDef,
|
|
18
|
+
) {
|
|
19
|
+
// Ascertain device type
|
|
20
|
+
const deviceType =
|
|
21
|
+
options.type || (await (await import('./patterns')).selectDeviceType());
|
|
22
|
+
|
|
23
|
+
// Ascertain organization
|
|
24
|
+
const organization =
|
|
25
|
+
options.organization?.toLowerCase() ||
|
|
26
|
+
(await (await import('./patterns')).getAndSelectOrganization());
|
|
27
|
+
|
|
28
|
+
// Create application
|
|
29
|
+
try {
|
|
30
|
+
const application = await getBalenaSdk().models.application.create({
|
|
31
|
+
name: params.name,
|
|
32
|
+
deviceType,
|
|
33
|
+
organization,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Output
|
|
37
|
+
const { capitalize } = await import('lodash');
|
|
38
|
+
console.log(
|
|
39
|
+
`${capitalize(resource)} created: slug "${
|
|
40
|
+
application.slug
|
|
41
|
+
}", device type "${deviceType}"`,
|
|
42
|
+
);
|
|
43
|
+
} catch (err) {
|
|
44
|
+
if ((err.message || '').toLowerCase().includes('unique')) {
|
|
45
|
+
// BalenaRequestError: Request error: "organization" and "app_name" must be unique.
|
|
46
|
+
throw new ExpectedError(
|
|
47
|
+
`Error: An app or block or fleet with the name "${params.name}" already exists in organization "${organization}".`,
|
|
48
|
+
);
|
|
49
|
+
} else if ((err.message || '').toLowerCase().includes('unauthorized')) {
|
|
50
|
+
// BalenaRequestError: Request error: Unauthorized
|
|
51
|
+
throw new ExpectedError(
|
|
52
|
+
`Error: You are not authorized to create ${resource}s in organization "${organization}".`,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
throw err;
|
|
57
|
+
}
|
|
58
|
+
}
|
package/lib/utils/patterns.ts
CHANGED
|
@@ -228,6 +228,24 @@ export async function selectOrganization(
|
|
|
228
228
|
});
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
+
export async function getAndSelectOrganization() {
|
|
232
|
+
const { getOwnOrganizations } = await import('./sdk');
|
|
233
|
+
const organizations = await getOwnOrganizations(getBalenaSdk(), {
|
|
234
|
+
$select: ['name', 'handle'],
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
if (organizations.length === 0) {
|
|
238
|
+
// User is not a member of any organizations (should not happen).
|
|
239
|
+
throw new Error('This account is not a member of any organizations');
|
|
240
|
+
} else if (organizations.length === 1) {
|
|
241
|
+
// User is a member of only one organization - use this.
|
|
242
|
+
return organizations[0].handle;
|
|
243
|
+
} else {
|
|
244
|
+
// User is a member of multiple organizations -
|
|
245
|
+
return selectOrganization(organizations);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
231
249
|
export async function awaitDeviceOsUpdate(
|
|
232
250
|
uuid: string,
|
|
233
251
|
targetOsVersion: string,
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "balena-cli",
|
|
3
|
-
"version": "16.7.
|
|
3
|
+
"version": "16.7.5",
|
|
4
4
|
"lockfileVersion": 2,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "balena-cli",
|
|
9
|
-
"version": "16.7.
|
|
9
|
+
"version": "16.7.5",
|
|
10
10
|
"hasInstallScript": true,
|
|
11
11
|
"license": "Apache-2.0",
|
|
12
12
|
"dependencies": {
|