feat: 新增租户 active 状态与统一禁用闸门
This commit is contained in:
1 parent
634f0e2b78
commit
0ff3d9a313
21 files changed
+855
-14
No files matched your search
@@ -1,11 +1,26 @@
|
||||
import { validationError } from "../errors.js";
|
||||
import { assertCorpActive } from "./active.js";
|
||||
import { CorpConfig, GlobalConfig } from "./types.js";
|
||||
|
||||
export type CorpResolveOptions = Pick<GlobalConfig, "stateful" | "defaultCorpId"> & {
|
||||
corpId?: string;
|
||||
/** Only the tenant status-management commands (`corps enable/disable`) may resolve a disabled corp. */
|
||||
allowDisabled?: boolean;
|
||||
};
|
||||
|
||||
export function resolveCorpConfig(
|
||||
corps: CorpConfig[],
|
||||
options: Pick<GlobalConfig, "stateful" | "defaultCorpId"> & { corpId?: string },
|
||||
options: CorpResolveOptions,
|
||||
candidates: string[] = []
|
||||
): CorpConfig {
|
||||
// Every successful lookup passes through the same gate. This is the single
|
||||
// choke point for CLI commands, MCP gateway commands, replay source/target
|
||||
// resolution and background workers — a disabled tenant is never executable.
|
||||
const accept = (found: CorpConfig): CorpConfig => {
|
||||
if (!options.allowDisabled) assertCorpActive(found);
|
||||
return found;
|
||||
};
|
||||
|
||||
const requestedCorpId = options.corpId?.trim() || undefined;
|
||||
const configuredCorpId = options.stateful
|
||||
? options.defaultCorpId?.trim() || undefined
|
||||
@@ -14,11 +29,11 @@ export function resolveCorpConfig(
|
||||
|
||||
if (selectedCorpId) {
|
||||
const exact = corps.find((item) => item.id === selectedCorpId);
|
||||
if (exact) return exact;
|
||||
if (exact) return accept(exact);
|
||||
const caseInsensitive = corps.find((item) => item.id.toLowerCase() === selectedCorpId.toLowerCase());
|
||||
if (caseInsensitive) return caseInsensitive;
|
||||
if (caseInsensitive) return accept(caseInsensitive);
|
||||
const byName = corps.find((item) => item.name.toLowerCase() === selectedCorpId.toLowerCase());
|
||||
if (byName) return byName;
|
||||
if (byName) return accept(byName);
|
||||
throw validationError(`No enterprise config found for ${selectedCorpId}`);
|
||||
}
|
||||
|
||||
@@ -28,7 +43,7 @@ export function resolveCorpConfig(
|
||||
}
|
||||
|
||||
const firstCorp = corps[0];
|
||||
if (firstCorp) return firstCorp;
|
||||
if (firstCorp) return accept(firstCorp);
|
||||
|
||||
throw validationError("No enterprise config found. Add a non-example JSON file under one of: " +
|
||||
(candidates.length ? candidates.join(", ") : "the configured enterprise directories"));
|
||||
|
||||
Reference in new issue
Block a user