secureboot: Retrieve the OS release & contract in one request

Change-type: patch
This commit is contained in:
Thodoris Greasidis 2023-05-19 19:14:31 +03:00
parent f0c8c37022
commit 83a5e7392a

View File

@ -200,21 +200,25 @@ export async function validateSecureBootOptionAndWarn(
throw new ExpectedError(`Error: No device type provided`); throw new ExpectedError(`Error: No device type provided`);
} }
const sdk = getBalenaSdk(); const sdk = getBalenaSdk();
const [OsRelease]: BalenaSdk.OsVersion[] = const releasePineOpts = {
await sdk.models.os.getAllOsVersions(`${slug}`, { $select: 'contract',
$select: 'id', $filter: { raw_version: `${version.replace(/^v/, '')}` },
$filter: { raw_version: `${version.replace(/^v/, '')}` }, } satisfies BalenaSdk.PineOptions<BalenaSdk.Release>;
}); // TODO: Remove the added type casting when the SDK returns the fully typed result
if (!OsRelease) { const [osRelease] = (await sdk.models.os.getAllOsVersions(
slug,
releasePineOpts,
)) as Array<
BalenaSdk.OsVersion &
BalenaSdk.PineTypedResult<BalenaSdk.Release, typeof releasePineOpts>
>;
if (!osRelease) {
throw new ExpectedError(`Error: No ${version} release for ${slug}`); throw new ExpectedError(`Error: No ${version} release for ${slug}`);
} }
const OsContract = await sdk.models.release.get(OsRelease.id, {
$select: 'contract', const contract = osRelease.contract ? JSON.parse(osRelease.contract) : null;
});
const yaml = require('js-yaml');
const contract = yaml.load(OsContract['contract']);
if ( if (
contract.provides.some((entry: Dictionary<string>) => { contract?.provides.some((entry: Dictionary<string>) => {
return entry.type === 'sw.feature' && entry.slug === 'secureboot'; return entry.type === 'sw.feature' && entry.slug === 'secureboot';
}) })
) { ) {