Bring Device Core settings to Mission UI and expose scoped B2 controls
Device Core qualification / qualify (push) Successful in 6m40s

This commit is contained in:
DCCONSTRUCTIONS
2026-09-30 22:43:54 +03:00
parent 8031ed76a2
commit 8941769b4c
12 changed files with 295 additions and 4 deletions
@@ -149,7 +149,9 @@ export function createB2Client(input, { fetchImpl } = {}) {
const value = await res.json().catch(() => null);
if (!res.ok) {
if (res.status === 401 || res.status === 403) { token = null; throw b2Error('b2_access_denied', 403); }
if (res.status === 409 && ['settings_revision_changed', 'settings_initial_read_required', 'settings_sim_observation_required'].includes(value?.error)) throw b2Error('b2_' + value.error, 409);
if (res.status === 409) throw b2Error('b2_conflict', 409);
if (res.status === 400) throw b2Error('b2_request_invalid', 400);
throw b2Error('b2_host_request_failed', 502);
}
if (!value || typeof value !== 'object') throw b2Error('b2_response_invalid', 502);
@@ -70,8 +70,43 @@ export class B2Infrastructure {
}));
return { items: results.flatMap((result) => result.items), hosts: results.map((result) => result.host) };
}
async tracker(actor, input) {
fields(input, ['contourId', 'deviceId', 'request']);
const projectId = ref(input.projectRef, 'project'), hostId = ref(input.hostRef, 'host');
const contourId = opaque(input.contourId), deviceId = opaque(input.deviceId);
const request = input.request;
const permissions = {
state: 'configuration.read', journal: 'audit.read', attempts: 'audit.read',
'firmware-download': 'configuration.read', 'firmware-upload': 'configuration.manage',
save: 'configuration.manage', 'profile-save': 'configuration.manage',
read: 'command.dispatch', apply: 'configuration.manage', command: 'command.dispatch', cancel: 'command.dispatch',
};
if (!request || typeof request !== 'object' || !permissions[request.action]) throw b2Error('b2_request_invalid');
const db = await this.pool.connect();
let source;
try {
await db.query('begin');
await findProjectWithCapability(db, actor, projectId, permissions[request.action]);
if (request.action === 'apply') await findProjectWithCapability(db, actor, projectId, 'command.dispatch');
source = (await db.query(`select s.* from device_b2_hosts s
join device_b2_host_views v on v.source_id=s.id
join device_b2_contour_links l on l.source_id=s.id and l.project_id=v.project_id
join device_infrastructure_hosts h on h.id=v.host_id and h.project_id=v.project_id
where v.host_id=$1 and v.project_id=$2 and l.contour_id=$3 and h.lifecycle_state='active'`,
[hostId, projectId, contourId])).rows[0];
if (!source) throw b2Error('b2_access_denied', 403);
await db.query('commit');
} catch (error) { await db.query('rollback'); throw error; } finally { db.release(); }
const remote = await this.clientFor(source);
const identity = await remote.call('/v2/identity');
if (identity.host_id !== source.remote_host_id) throw b2Error('b2_host_identity_mismatch');
// VPS checks the device's actual contour as well; a forged device ID cannot
// borrow the host administrator credential from another project.
return remote.call(`/v2/contours/${contourId}/devices/${deviceId}/settings`, request);
}
async execute(actor, input, requestId) {
if (input.action === 'inventory') return this.inventory(actor, input);
if (input.action === 'tracker') return this.tracker(actor, input);
const projectId = ref(input.projectRef, 'project');
const hostId = ref(input.hostRef, 'host');
const action = input.action;