已完成管理后台第一批只读功能的 ASP.NET Core 10 迁移:
原生接口:context、dashboard、schools、school-organization、admins、exams 保持超级、校级、班级管理员的数据范围及权限隔离 其余管理写入、审批流和考务编排仍由 Node 转发 新增 ADMIN_NATIVE_READS_ENABLED=true 开关,并强制要求原生认证和共享 Redis
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
namespace Eis.Infrastructure.Administration;
|
||||
|
||||
public sealed record AdminMigrationOptions(bool NativeReadsEnabled)
|
||||
{
|
||||
public static AdminMigrationOptions FromEnvironment(
|
||||
bool configuredNativeReadsEnabled,
|
||||
bool authenticationNativeEnabled,
|
||||
bool sharesLegacySessions)
|
||||
{
|
||||
var enabled = ParseBoolean(
|
||||
Environment.GetEnvironmentVariable("ADMIN_NATIVE_READS_ENABLED"),
|
||||
configuredNativeReadsEnabled);
|
||||
if (enabled && !authenticationNativeEnabled)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"启用原生管理端读取接口前必须同时设置 AUTH_NATIVE_ENABLED=true");
|
||||
}
|
||||
|
||||
var allowMemoryForIsolatedTesting = ParseBoolean(
|
||||
Environment.GetEnvironmentVariable("ADMIN_NATIVE_ALLOW_MEMORY"),
|
||||
fallback: false);
|
||||
if (enabled && !sharesLegacySessions && !allowMemoryForIsolatedTesting)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"管理端仍有写入接口需要转发给 Node;启用原生管理端读取接口必须配置共享 Redis 会话");
|
||||
}
|
||||
|
||||
return new AdminMigrationOptions(enabled);
|
||||
}
|
||||
|
||||
private static bool ParseBoolean(string? value, bool fallback) => value?.Trim().ToLowerInvariant() switch
|
||||
{
|
||||
"1" or "true" or "yes" or "on" => true,
|
||||
"0" or "false" or "no" or "off" => false,
|
||||
_ => fallback
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user