feat(core): add ontology-backed asset and host runtime
This commit is contained in:
@@ -46,6 +46,29 @@ const managementRoutes = new Map([
|
||||
"/internal/v1/management/device-configurations:set-desired",
|
||||
"device_configuration_desired.set",
|
||||
],
|
||||
["/internal/v1/management/assets:ensure", "asset.ensure"],
|
||||
["/internal/v1/management/asset-bindings:ensure", "asset_binding.ensure"],
|
||||
["/internal/v1/management/asset-bindings:close", "asset_binding.close"],
|
||||
[
|
||||
"/internal/v1/management/infrastructure-hosts:ensure",
|
||||
"infrastructure_host.ensure",
|
||||
],
|
||||
[
|
||||
"/internal/v1/management/infrastructure-endpoints:ensure",
|
||||
"infrastructure_endpoint.ensure",
|
||||
],
|
||||
[
|
||||
"/internal/v1/management/infrastructure-deployments:ensure",
|
||||
"infrastructure_deployment.ensure",
|
||||
],
|
||||
[
|
||||
"/internal/v1/management/infrastructure-service-instances:ensure",
|
||||
"infrastructure_service_instance.ensure",
|
||||
],
|
||||
[
|
||||
"/internal/v1/management/health-observations:record",
|
||||
"health_observation.record",
|
||||
],
|
||||
]);
|
||||
|
||||
export function createControlCoreApp({
|
||||
@@ -295,6 +318,34 @@ export function createControlCoreApp({
|
||||
return writeJson(response, 200, { ok: true, workspace });
|
||||
}
|
||||
|
||||
const ontologyProjectId = projectOntologyId(requestUrl.pathname);
|
||||
if (request.method === "GET" && ontologyProjectId) {
|
||||
if (!managementApiEnabled) {
|
||||
return writeJson(response, 404, {
|
||||
ok: false,
|
||||
error: "device_management_api_disabled",
|
||||
});
|
||||
}
|
||||
if (!matchesBearer(request.headers.authorization, managementToken)) {
|
||||
return writeJson(response, 401, {
|
||||
ok: false,
|
||||
error: "device_management_auth_required",
|
||||
});
|
||||
}
|
||||
if (typeof repository.getProjectOntologyProjection !== "function") {
|
||||
return writeJson(response, 503, {
|
||||
ok: false,
|
||||
error: "device_query_repository_unavailable",
|
||||
});
|
||||
}
|
||||
const actor = managementActorFromHeaders(request.headers);
|
||||
const projection = await repository.getProjectOntologyProjection(
|
||||
actor,
|
||||
ontologyProjectId,
|
||||
);
|
||||
return writeJson(response, 200, { ok: true, projection });
|
||||
}
|
||||
|
||||
if (
|
||||
request.method === "POST"
|
||||
&& requestUrl.pathname === "/internal/v1/device-discoveries:observe"
|
||||
@@ -408,6 +459,13 @@ function projectWorkspaceId(pathname) {
|
||||
return match?.[1]?.toLowerCase() ?? null;
|
||||
}
|
||||
|
||||
function projectOntologyId(pathname) {
|
||||
const match = pathname.match(
|
||||
/^\/internal\/v1\/query\/projects\/([0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})\/ontology$/i,
|
||||
);
|
||||
return match?.[1]?.toLowerCase() ?? null;
|
||||
}
|
||||
|
||||
function managementActorFromHeaders(headers) {
|
||||
return normalizeManagementActor({
|
||||
userRef: singleHeader(headers["x-nodedc-user-ref"]),
|
||||
|
||||
Reference in New Issue
Block a user