|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +/** |
| 4 | + * Multi-node authorization gate (open mechanism). |
| 5 | + * |
| 6 | + * The open framework ships **no gate** — multi-node is always allowed. A |
| 7 | + * distribution (e.g. the Enterprise Edition) registers a gate to authorize |
| 8 | + * whether the runtime may enable a multi-node (remote-driver) topology — for |
| 9 | + * example, an EE license check. The framework deliberately knows nothing about |
| 10 | + * *why* a gate allows or denies; it only consults the registered decision. |
| 11 | + * |
| 12 | + * When a gate denies, the caller (e.g. `os serve`) **downgrades to single-node** |
| 13 | + * rather than failing — multi-node is an add-on, not a precondition for the |
| 14 | + * runtime to serve. This is distinct from the split-brain guard, which throws |
| 15 | + * on an outright misconfiguration (memory driver declared multi-node). |
| 16 | + */ |
| 17 | +export interface MultiNodeGate { |
| 18 | + /** |
| 19 | + * Called before the runtime enables a remote-driver (multi-node) topology. |
| 20 | + * Return `allowed: false` to force single-node; `reason` is surfaced in logs. |
| 21 | + */ |
| 22 | + allowMultiNode(): { allowed: boolean; reason?: string }; |
| 23 | +} |
| 24 | + |
| 25 | +let registered: MultiNodeGate | undefined; |
| 26 | + |
| 27 | +/** |
| 28 | + * Register the multi-node authorization gate. Last registration wins. A |
| 29 | + * distribution calls this at boot (before the cluster topology is resolved). |
| 30 | + */ |
| 31 | +export function registerMultiNodeGate(gate: MultiNodeGate): void { |
| 32 | + registered = gate; |
| 33 | +} |
| 34 | + |
| 35 | +/** |
| 36 | + * Resolve the multi-node decision. With no gate registered (open framework), |
| 37 | + * multi-node is allowed. |
| 38 | + */ |
| 39 | +export function checkMultiNodeAllowed(): { allowed: boolean; reason?: string } { |
| 40 | + return registered ? registered.allowMultiNode() : { allowed: true }; |
| 41 | +} |
| 42 | + |
| 43 | +/** Clear the registered gate. For tests. */ |
| 44 | +export function __resetMultiNodeGate(): void { |
| 45 | + registered = undefined; |
| 46 | +} |
0 commit comments