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:
Felipe Lalanne 2021-11-04 18:55:50 +00:00
parent b2b1b111b3
commit b11696144f

View File

@ -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),
),