Files
rust-discovery/web/src/catalog-check.tsx
T
2026-11-15 14:11:06 +01:00

29 lines
2.9 KiB
TypeScript

import type { RecordValue } from './api';
function object(value: unknown): RecordValue | null { return value !== null && typeof value === 'object' && !Array.isArray(value) ? value as RecordValue : null; }
const exact = (value: RecordValue, keys: string[]) => Object.keys(value).every(key => keys.includes(key));
const date = (value: unknown): value is string => typeof value === 'string' && value.length <= 40 && Number.isFinite(Date.parse(value));
const positive = (value: unknown) => Number.isSafeInteger(value) && Number(value) > 0;
export function CatalogCheckNotice({ device }: { device: unknown }) {
const inventory = object(object(device)?.inventory), entries = inventory?.observations;
if (!Array.isArray(entries)) return null;
const matches = entries.map(object).filter(entry => entry?.scope === 'linux.agent_update.catalog');
if (!matches.length) return null;
const invalid = <p role="alert">Gespeicherter Releasekatalogcheck ist ungültig; kein Updatebeleg.</p>;
if (matches.length !== 1) return invalid;
const entry = matches[0]!, report = object(entry.data);
if (!report || entry.source_id !== 'agent:cached-release-catalog-v1' || entry.completeness !== 'complete' || entry.truncated !== false || !date(entry.observed_at)
|| !exact(report, ['schema_version', 'source_id', 'checked_at', 'status', 'candidate']) || report.schema_version !== 1 || report.source_id !== 'mtls:release-catalog-v1'
|| !date(report.checked_at) || Date.parse(report.checked_at) > Date.parse(entry.observed_at) + 1000) return invalid;
const status = report.status, candidate = object(report.candidate), available = status === 'available' || status === 'current';
if (!(available || status === 'not_configured' || status === 'unavailable') || entry.quality !== (available ? 'valid' : status === 'not_configured' ? 'unknown' : 'error')) return invalid;
if (available ? !candidate || !exact(candidate, ['release_id', 'release_sequence', 'version', 'manifest_sha256', 'keyring_generation'])
|| typeof candidate.release_id !== 'string' || !/^[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}$/.test(candidate.release_id)
|| !positive(candidate.release_sequence) || !positive(candidate.keyring_generation) || typeof candidate.version !== 'string' || !/^[A-Za-z0-9.+_-]{1,64}$/.test(candidate.version)
|| typeof candidate.manifest_sha256 !== 'string' || !/^[a-f0-9]{64}$/.test(candidate.manifest_sha256) : Object.hasOwn(report, 'candidate')) return invalid;
return <aside aria-label="Gespeicherter Releasekatalogcheck"><h4>Passiver Releasekatalogcheck</h4>
<p>Status: {String(status)} · geprüft: <time>{report.checked_at}</time></p><p>Cache im Inventar gelesen: <time>{entry.observed_at}</time></p>
{candidate && <p>Release: {String(candidate.version)} · Sequenz {String(candidate.release_sequence)}<br/>Manifest SHA-256: <code>{String(candidate.manifest_sha256)}</code></p>}
<p>Katalogmetadaten; keine Installation oder Ausführungserlaubnis.</p></aside>;
}