refactor(gateway): extract connect and role policy logic

This commit is contained in:
Peter Steinberger
2026-02-21 19:47:17 +01:00
parent f97c45c5b5
commit 51149fcaf1
7 changed files with 342 additions and 157 deletions

View File

@@ -0,0 +1,23 @@
import { isNodeRoleMethod } from "./method-scopes.js";
export const GATEWAY_ROLES = ["operator", "node"] as const;
export type GatewayRole = (typeof GATEWAY_ROLES)[number];
export function parseGatewayRole(roleRaw: unknown): GatewayRole | null {
if (roleRaw === "operator" || roleRaw === "node") {
return roleRaw;
}
return null;
}
export function roleCanSkipDeviceIdentity(role: GatewayRole, sharedAuthOk: boolean): boolean {
return role === "operator" && sharedAuthOk;
}
export function isRoleAuthorizedForMethod(role: GatewayRole, method: string): boolean {
if (isNodeRoleMethod(method)) {
return role === "node";
}
return role === "operator";
}