mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-04-18 08:10:04 +00:00
Only report current state of apps in the target state
If an app is not in the target state means the supervisor no longer has permissions to that app hence it cannot report on it. When moving between apps, there is a transitional period where containers and images from both apps can be in the current state, therefore filtering is needed to prevent getting 401 errors from the API.
This commit is contained in:
parent
b2b1b111b3
commit
b11696144f
@ -42,6 +42,7 @@ import {
|
||||
TargetState,
|
||||
DeviceState,
|
||||
DeviceReport,
|
||||
AppState,
|
||||
} from './types';
|
||||
import * as dbFormat from './device-state/db-format';
|
||||
import * as apiKeys from './lib/api-keys';
|
||||
@ -611,6 +612,19 @@ export async function getCurrentForReport(
|
||||
): Promise<DeviceState> {
|
||||
const apps = await applicationManager.getState();
|
||||
|
||||
// Fiter current apps by the target state as the supervisor cannot
|
||||
// report on apps for which it doesn't have API permissions
|
||||
const targetAppUuids = Object.keys(await applicationManager.getTargetApps());
|
||||
const appsForReport = Object.keys(apps)
|
||||
.filter((appUuid) => targetAppUuids.includes(appUuid))
|
||||
.reduce(
|
||||
(filteredApps, appUuid) => ({
|
||||
...filteredApps,
|
||||
[appUuid]: apps[appUuid],
|
||||
}),
|
||||
{} as { [appUuid: string]: AppState },
|
||||
);
|
||||
|
||||
const { name, uuid, localMode } = await config.getMany([
|
||||
'name',
|
||||
'uuid',
|
||||
@ -636,7 +650,7 @@ export async function getCurrentForReport(
|
||||
...currentVolatile,
|
||||
...systemInfo,
|
||||
name,
|
||||
apps,
|
||||
apps: appsForReport,
|
||||
},
|
||||
(__, key) => omitFromReport.includes(key),
|
||||
),
|
||||
|
Loading…
x
Reference in New Issue
Block a user