Manage shared ARNavi VPS contours and application keys from infrastructure

This commit is contained in:
DCCONSTRUCTIONS
2026-09-30 15:34:39 +03:00
parent 6ca6738bab
commit 1828a05332
22 changed files with 1099 additions and 2 deletions
@@ -171,6 +171,19 @@ export function createDeviceManagerServer({
const workspace = await coreClient.getWorkspace(context.actor, projectRef);
return sendJson(response, 200, { ok: true, workspace });
}
if (request.method === "POST" && url.pathname === "/api/device-manager/b2/infrastructure") {
if (!coreClient.b2Infrastructure) throw serviceError("b2_infrastructure_unavailable", 503);
// This route handles keys. Require JSON and an explicit same-origin
// browser request in addition to the authenticated server-side session.
if (request.headers.origin !== `${auth.authRequired ? 'https:' : url.protocol}//${request.headers.host}` || !String(request.headers["content-type"] || "").startsWith("application/json")) {
throw serviceError("device_manager_origin_required", 403);
}
const requestId = singleHeader(request.headers["idempotency-key"]);
if (!/^[a-f0-9]{32}$/.test(requestId)) throw serviceError("b2_request_id_invalid", 400);
const input = await readJsonBody(request, 64 * 1024);
const result = await coreClient.b2Infrastructure(context.actor, input, requestId);
return sendJson(response, 200, { ok: true, result });
}
const command = mutationRoutes.get(url.pathname);
if (request.method === "POST" && command) {
const idempotencyKey = singleHeader(request.headers["idempotency-key"]);
@@ -373,7 +386,7 @@ function normalizeStatus(value) {
function safeError(error) {
const value = String(error?.message || "");
return /^(?:device|nodedc)_[a-z0-9._:-]{2,160}$/.test(value)
return /^(?:device|nodedc|b2)_[a-z0-9._:-]{2,160}$/.test(value)
? value
: "device_manager_internal_error";
}