@balena/open-balena-api 31.2.7-build-service-install-filter-gc-df260b150b12df0176acf3ee6f888cfe3479571a-1 → 31.2.7-build-move-device-service-propagate-hook-178b415458627d3f2c07633150011d741a1bb00d-1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/features/ci-cd/tasks/service-installs.js +40 -43
- package/dist/features/ci-cd/tasks/service-installs.js.map +1 -1
- package/dist/features/service-install/hooks/backfill-service-install-on-device-service-env-var.js +41 -0
- package/dist/features/service-install/hooks/backfill-service-install-on-device-service-env-var.js.map +1 -0
- package/dist/features/service-install/hooks/index.d.ts +1 -1
- package/dist/features/service-install/hooks/index.js +1 -1
- package/dist/features/service-install/hooks/index.js.map +1 -1
- package/dist/translations/v7/hooks.js +31 -1
- package/dist/translations/v7/hooks.js.map +1 -1
- package/package.json +2 -2
- package/dist/features/service-install/hooks/backfill-device-service-environment-variable.js +0 -26
- package/dist/features/service-install/hooks/backfill-device-service-environment-variable.js.map +0 -1
- /package/dist/features/service-install/hooks/{backfill-device-service-environment-variable.d.ts → backfill-service-install-on-device-service-env-var.d.ts} +0 -0
@@ -67,57 +67,54 @@ const createServiceInstalls = async ({ devices, }) => {
|
|
67
67
|
return [device.id, [...new Set(deviceServiceIds)]];
|
68
68
|
}));
|
69
69
|
const serviceIds = [...new Set([...targetServicesByDevice.values()].flat())];
|
70
|
-
|
70
|
+
const missingServiceFilters = serviceIds.map((serviceId) => ({
|
71
|
+
$not: {
|
72
|
+
service_install: {
|
73
|
+
$any: {
|
74
|
+
$alias: 'si',
|
75
|
+
$expr: {
|
76
|
+
si: {
|
77
|
+
installs__service: serviceId,
|
78
|
+
},
|
79
|
+
},
|
80
|
+
},
|
81
|
+
},
|
82
|
+
},
|
83
|
+
}));
|
84
|
+
if (missingServiceFilters.length === 0) {
|
71
85
|
console.info('[service-install-task] No service installs to create');
|
72
86
|
return 0;
|
73
87
|
}
|
74
|
-
const devicesToAddServiceInstalls = await (
|
75
|
-
|
76
|
-
|
77
|
-
|
88
|
+
const devicesToAddServiceInstalls = (await api.resin.get({
|
89
|
+
resource: 'device',
|
90
|
+
passthrough: { req: permissions.rootRead },
|
91
|
+
options: {
|
92
|
+
$select: 'id',
|
93
|
+
$expand: {
|
78
94
|
service_install: {
|
79
|
-
$
|
80
|
-
|
81
|
-
$
|
82
|
-
si: {
|
83
|
-
installs__service: serviceId,
|
84
|
-
},
|
85
|
-
},
|
95
|
+
$select: 'installs__service',
|
96
|
+
$filter: {
|
97
|
+
installs__service: { $in: serviceIds },
|
86
98
|
},
|
87
99
|
},
|
88
100
|
},
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
service_install: {
|
97
|
-
$select: 'installs__service',
|
98
|
-
$filter: {
|
99
|
-
installs__service: { $in: serviceIds },
|
100
|
-
},
|
101
|
-
},
|
102
|
-
},
|
103
|
-
$filter: {
|
104
|
-
id: { $in: devices },
|
105
|
-
...(missingServiceFilters.length === 1
|
106
|
-
? missingServiceFilters[0]
|
107
|
-
: {
|
108
|
-
$or: missingServiceFilters,
|
109
|
-
}),
|
110
|
-
},
|
101
|
+
$filter: {
|
102
|
+
id: { $in: devices },
|
103
|
+
...(missingServiceFilters.length === 1
|
104
|
+
? missingServiceFilters[0]
|
105
|
+
: {
|
106
|
+
$or: missingServiceFilters,
|
107
|
+
}),
|
111
108
|
},
|
112
|
-
}
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
}
|
120
|
-
})
|
109
|
+
},
|
110
|
+
})).map((device) => {
|
111
|
+
// Transform the device to the simpler object we will need later which is smaller
|
112
|
+
// and will allow the larger version to be garbage collected sooner
|
113
|
+
return {
|
114
|
+
id: device.id,
|
115
|
+
serviceInstalls: device.service_install.map((si) => si.installs__service.__id),
|
116
|
+
};
|
117
|
+
});
|
121
118
|
// This is already batched at one level, does it make sense to batch it again?
|
122
119
|
const remainingDevices = new Set(devices);
|
123
120
|
let totalSiCreated = 0;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"service-installs.js","sourceRoot":"","sources":["../../../../src/features/ci-cd/tasks/service-installs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,CAAC,MAAM,QAAQ,CAAC;AACvB,OAAO,EACN,wBAAwB,EACxB,8CAA8C,GAC9C,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,0BAA0B,EAAE,MAAM,wCAAwC,CAAC;AAEpF,MAAM,MAAM,GAAG;IACd,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACX,OAAO,EAAE;YACR,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;SACzB;KACD;IACD,QAAQ,EAAE,CAAC,SAAS,CAAC;CACrB,CAAC;AAEF,MAAM,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC;AAM1B,KAAK,CAAC,cAAc,CACnB,yBAAyB,EACzB,KAAK,EAAE,OAAO,EAAE,EAAE;IACjB,IAAI,CAAC;QACJ,MAAM,cAAc,GAAG,MAAM,qBAAqB,CACjD,OAAO,CAAC,MAAyC,CACjD,CAAC;QACF,OAAO,CAAC,IAAI,CACX,kCAAkC,cAAc,mBAAmB,CACnE,CAAC;QACF,OAAO;YACN,MAAM,EAAE,WAAW;SACnB,CAAC;IACH,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACZ,OAAO,CAAC,KAAK,CACZ,2DAA2D,CAAC,EAAE,CAC9D,CAAC;QACF,OAAO;YACN,KAAK,EAAE,GAAG,CAAC,EAAE;YACb,MAAM,EAAE,QAAQ;SAChB,CAAC;IACH,CAAC;AACF,CAAC,EACD,MAAM,CACN,CAAC;AAEF,MAAM,qBAAqB,GAAG,KAAK,EAAE,EACpC,OAAO,GAC0B,EAAE,EAAE;IACrC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAA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AG,sBAAsB,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAE7E,
|
1
|
+
{"version":3,"file":"service-installs.js","sourceRoot":"","sources":["../../../../src/features/ci-cd/tasks/service-installs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,CAAC,MAAM,QAAQ,CAAC;AACvB,OAAO,EACN,wBAAwB,EACxB,8CAA8C,GAC9C,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,0BAA0B,EAAE,MAAM,wCAAwC,CAAC;AAEpF,MAAM,MAAM,GAAG;IACd,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACX,OAAO,EAAE;YACR,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;SACzB;KACD;IACD,QAAQ,EAAE,CAAC,SAAS,CAAC;CACrB,CAAC;AAEF,MAAM,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC;AAM1B,KAAK,CAAC,cAAc,CACnB,yBAAyB,EACzB,KAAK,EAAE,OAAO,EAAE,EAAE;IACjB,IAAI,CAAC;QACJ,MAAM,cAAc,GAAG,MAAM,qBAAqB,CACjD,OAAO,CAAC,MAAyC,CACjD,CAAC;QACF,OAAO,CAAC,IAAI,CACX,kCAAkC,cAAc,mBAAmB,CACnE,CAAC;QACF,OAAO;YACN,MAAM,EAAE,WAAW;SACnB,CAAC;IACH,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACZ,OAAO,CAAC,KAAK,CACZ,2DAA2D,CAAC,EAAE,CAC9D,CAAC;QACF,OAAO;YACN,KAAK,EAAE,GAAG,CAAC,EAAE;YACb,MAAM,EAAE,QAAQ;SAChB,CAAC;IACH,CAAC;AACF,CAAC,EACD,MAAM,CACN,CAAC;AAEF,MAAM,qBAAqB,GAAG,KAAK,EAAE,EACpC,OAAO,GAC0B,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AkB,GAAG,MAAM,CAAC,eAAe,CAAC;gBAClD,MAAM,gBAAgB,GAAG,CAAC,CAAC,UAAU,CACpC,gBAAgB,EAChB,kBAAkB,CAClB,CAAC;gBAEF,MAAM,OAAO,CAAC,GAAG,CAChB,gBAAgB,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;oBACxC,+DAA+D;oBAC/D,MAAM,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC;wBACpB,QAAQ,EAAE,iBAAiB;wBAC3B,WAAW,EAAE,EAAE,GAAG,EAAE,WAAW,CAAC,IAAI,EAAE,EAAE,EAAE;wBAC1C,IAAI,EAAE;4BACL,MAAM,EAAE,MAAM,CAAC,EAAE;4BACjB,iBAAiB,EAAE,SAAS;yBAC5B;wBACD,OAAO,EAAE,EAAE,cAAc,EAAE,KAAK,EAAE;qBAClC,CAAC,CAAC;gBACJ,CAAC,CAAC,CACF,CAAC;gBAEF,cAAc,IAAI,gBAAgB,CAAC,MAAM,CAAC;YAC3C,CAAC;YACD,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YACnC,sBAAsB,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC1C,CAAC;QACD,OAAO,cAAc,CAAC;IACvB,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/features/service-install/hooks/backfill-service-install-on-device-service-env-var.js
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
import { hooks, errors } from '@balena/pinejs';
|
2
|
+
async function backfillServiceInstall({ request, api, }) {
|
3
|
+
const { device: deviceId, service: serviceId } = request.values;
|
4
|
+
if (deviceId == null && serviceId == null) {
|
5
|
+
return;
|
6
|
+
}
|
7
|
+
if ((deviceId == null && serviceId != null) ||
|
8
|
+
(deviceId != null && serviceId == null)) {
|
9
|
+
throw new errors.BadRequestError('Both or none of device and service must be specified');
|
10
|
+
}
|
11
|
+
let si = await api.get({
|
12
|
+
resource: 'service_install',
|
13
|
+
id: {
|
14
|
+
device: deviceId,
|
15
|
+
installs__service: serviceId,
|
16
|
+
},
|
17
|
+
options: {
|
18
|
+
$select: ['id'],
|
19
|
+
},
|
20
|
+
});
|
21
|
+
if (si == null) {
|
22
|
+
si = await api.post({
|
23
|
+
resource: 'service_install',
|
24
|
+
body: {
|
25
|
+
device: deviceId,
|
26
|
+
installs__service: serviceId,
|
27
|
+
},
|
28
|
+
});
|
29
|
+
}
|
30
|
+
if (si == null) {
|
31
|
+
throw new errors.BadRequestError(`No service install exists for device: ${deviceId} and service ${serviceId} and one could not be created`);
|
32
|
+
}
|
33
|
+
request.values.service_install = si.id;
|
34
|
+
}
|
35
|
+
hooks.addPureHook('POST', 'resin', 'device_service_environment_variable', {
|
36
|
+
POSTPARSE: backfillServiceInstall,
|
37
|
+
});
|
38
|
+
hooks.addPureHook('PATCH', 'resin', 'device_service_environment_variable', {
|
39
|
+
POSTPARSE: backfillServiceInstall,
|
40
|
+
});
|
41
|
+
//# sourceMappingURL=backfill-service-install-on-device-service-env-var.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"backfill-service-install-on-device-service-env-var.js","sourceRoot":"","sources":["../../../../src/features/service-install/hooks/backfill-service-install-on-device-service-env-var.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAkB,MAAM,gBAAgB,CAAC;AAE/D,KAAK,UAAU,sBAAsB,CAAC,EACrC,OAAO,EACP,GAAG,GAC0B;IAC7B,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAEhE,IAAI,QAAQ,IAAI,IAAI,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;QAC3C,OAAO;IACR,CAAC;IAED,IACC,CAAC,QAAQ,IAAI,IAAI,IAAI,SAAS,IAAI,IAAI,CAAC;QACvC,CAAC,QAAQ,IAAI,IAAI,IAAI,SAAS,IAAI,IAAI,CAAC,EACtC,CAAC;QACF,MAAM,IAAI,MAAM,CAAC,eAAe,CAC/B,sDAAsD,CACtD,CAAC;IACH,CAAC;IAED,IAAI,EAAE,GAAG,MAAM,GAAG,CAAC,GAAG,CAAC;QACtB,QAAQ,EAAE,iBAAiB;QAC3B,EAAE,EAAE;YACH,MAAM,EAAE,QAAQ;YAChB,iBAAiB,EAAE,SAAS;SAC5B;QACD,OAAO,EAAE;YACR,OAAO,EAAE,CAAC,IAAI,CAAC;SACf;KACD,CAAC,CAAC;IAEH,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC;QAChB,EAAE,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC;YACnB,QAAQ,EAAE,iBAAiB;YAC3B,IAAI,EAAE;gBACL,MAAM,EAAE,QAAQ;gBAChB,iBAAiB,EAAE,SAAS;aAC5B;SACD,CAAC,CAAC;IACJ,CAAC;IAED,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC;QAChB,MAAM,IAAI,MAAM,CAAC,eAAe,CAC/B,yCAAyC,QAAQ,gBAAgB,SAAS,+BAA+B,CACzG,CAAC;IACH,CAAC;IAED,OAAO,CAAC,MAAM,CAAC,eAAe,GAAG,EAAE,CAAC,EAAE,CAAC;AACxC,CAAC;AAED,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,qCAAqC,EAAE;IACzE,SAAS,EAAE,sBAAsB;CACjC,CAAC,CAAC;AAEH,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,qCAAqC,EAAE;IAC1E,SAAS,EAAE,sBAAsB;CACjC,CAAC,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
import './backfill-device-service-
|
1
|
+
import './backfill-service-install-on-device-service-env-var.js';
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import './backfill-device-service-
|
1
|
+
import './backfill-service-install-on-device-service-env-var.js';
|
2
2
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/features/service-install/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/features/service-install/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,yDAAyD,CAAC"}
|
@@ -1,2 +1,32 @@
|
|
1
|
-
|
1
|
+
import { hooks, sbvrUtils, errors } from '@balena/pinejs';
|
2
|
+
const addReadOnlyHook = (methods, resource, hook) => {
|
3
|
+
methods.map((method) => {
|
4
|
+
hooks.addHook(method, 'v7', resource, {
|
5
|
+
...hook,
|
6
|
+
sideEffects: false,
|
7
|
+
readOnlyTx: true,
|
8
|
+
});
|
9
|
+
});
|
10
|
+
};
|
11
|
+
addReadOnlyHook(['POST', 'PATCH', 'PUT'], 'device_service_environment_variable', {
|
12
|
+
POSTPARSE: async ({ request, api }) => {
|
13
|
+
const { service_install: siId } = request.values;
|
14
|
+
if (siId == null) {
|
15
|
+
return;
|
16
|
+
}
|
17
|
+
const si = await sbvrUtils.api.resin.get({
|
18
|
+
resource: 'service_install',
|
19
|
+
passthrough: api.passthrough,
|
20
|
+
id: siId,
|
21
|
+
options: {
|
22
|
+
$select: ['device', 'service'],
|
23
|
+
},
|
24
|
+
});
|
25
|
+
if (si == null) {
|
26
|
+
throw new errors.UnauthorizedError();
|
27
|
+
}
|
28
|
+
request.values.device = si.device.__id;
|
29
|
+
request.values.service = si.service.__id;
|
30
|
+
},
|
31
|
+
});
|
2
32
|
//# sourceMappingURL=hooks.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../src/translations/v7/hooks.ts"],"names":[],"mappings":""}
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../src/translations/v7/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE1D,MAAM,eAAe,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description": "Internet of things, Made Simple",
|
4
|
-
"version": "31.2.7-build-service-
|
4
|
+
"version": "31.2.7-build-move-device-service-propagate-hook-178b415458627d3f2c07633150011d741a1bb00d-1",
|
5
5
|
"license": "AGPL-3.0",
|
6
6
|
"repository": {
|
7
7
|
"type": "git",
|
@@ -166,6 +166,6 @@
|
|
166
166
|
"loader": "ts-node/esm/transpile-only"
|
167
167
|
},
|
168
168
|
"versionist": {
|
169
|
-
"publishedAt": "2024-11-
|
169
|
+
"publishedAt": "2024-11-19T18:45:16.883Z"
|
170
170
|
}
|
171
171
|
}
|
@@ -1,26 +0,0 @@
|
|
1
|
-
import { hooks, errors } from '@balena/pinejs';
|
2
|
-
async function backfillDeviceAndService({ request, api, }) {
|
3
|
-
const { service_install: siId } = request.values;
|
4
|
-
if (siId == null) {
|
5
|
-
return;
|
6
|
-
}
|
7
|
-
const si = await api.get({
|
8
|
-
resource: 'service_install',
|
9
|
-
id: siId,
|
10
|
-
options: {
|
11
|
-
$select: ['device', 'service'],
|
12
|
-
},
|
13
|
-
});
|
14
|
-
if (si == null) {
|
15
|
-
throw new errors.UnauthorizedError();
|
16
|
-
}
|
17
|
-
request.values.device = si.device.__id;
|
18
|
-
request.values.service = si.service.__id;
|
19
|
-
}
|
20
|
-
hooks.addPureHook('POST', 'resin', 'device_service_environment_variable', {
|
21
|
-
POSTPARSE: backfillDeviceAndService,
|
22
|
-
});
|
23
|
-
hooks.addPureHook('PATCH', 'resin', 'device_service_environment_variable', {
|
24
|
-
POSTPARSE: backfillDeviceAndService,
|
25
|
-
});
|
26
|
-
//# sourceMappingURL=backfill-device-service-environment-variable.js.map
|
package/dist/features/service-install/hooks/backfill-device-service-environment-variable.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"backfill-device-service-environment-variable.js","sourceRoot":"","sources":["../../../../src/features/service-install/hooks/backfill-device-service-environment-variable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAkB,MAAM,gBAAgB,CAAC;AAE/D,KAAK,UAAU,wBAAwB,CAAC,EACvC,OAAO,EACP,GAAG,GAC0B;IAC7B,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAEjD,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;QAClB,OAAO;IACR,CAAC;IAED,MAAM,EAAE,GAAG,MAAM,GAAG,CAAC,GAAG,CAAC;QACxB,QAAQ,EAAE,iBAAiB;QAC3B,EAAE,EAAE,IAAI;QACR,OAAO,EAAE;YACR,OAAO,EAAE,CAAC,QAAQ,EAAE,SAAS,CAAC;SAC9B;KACD,CAAC,CAAC;IAEH,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC;QAChB,MAAM,IAAI,MAAM,CAAC,iBAAiB,EAAE,CAAC;IACtC,CAAC;IAED,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC;IACvC,OAAO,CAAC,MAAM,CAAC,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;AAC1C,CAAC;AAED,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,qCAAqC,EAAE;IACzE,SAAS,EAAE,wBAAwB;CACnC,CAAC,CAAC;AAEH,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,qCAAqC,EAAE;IAC1E,SAAS,EAAE,wBAAwB;CACnC,CAAC,CAAC"}
|