mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 22:54:31 +00:00
refactor(gateway): extract connect and role policy logic
This commit is contained in:
23
src/gateway/role-policy.ts
Normal file
23
src/gateway/role-policy.ts
Normal 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";
|
||||
}
|
||||
Reference in New Issue
Block a user