refactor: inject token runtime configuration

This commit is contained in:
jxxghp
2026-08-23 01:14:12 +08:00
parent 5395bbff54
commit 690ebe0c02
8 changed files with 75 additions and 12 deletions
+26
View File
@@ -72,6 +72,16 @@ class TransferRetryConfig:
max_failed_retries: Any
@dataclass(frozen=True, slots=True)
class TokenRuntimeConfig:
"""令牌编解码在一次宿主生命周期内使用的安全配置快照。"""
secret_key: str
resource_secret_key: str
access_token_expire_minutes: int
resource_access_token_expire_seconds: int
@dataclass(frozen=True, slots=True)
class ApiRuntimeConfig:
"""单次 API 请求使用的宿主配置快照。"""
@@ -318,6 +328,7 @@ class SystemConfigService:
_configured_system_config: SystemConfigService | None = None
_transfer_retry_config_provider: Callable[[], TransferRetryConfig] | None = None
_token_runtime_config_provider: Callable[[], TokenRuntimeConfig] | None = None
_runtime_configuration: RuntimeConfiguration | None = None
_runtime_settings_service: RuntimeSettingsService | None = None
@@ -350,6 +361,21 @@ def get_transfer_retry_config() -> TransferRetryConfig:
return _transfer_retry_config_provider()
def configure_token_runtime_config(
provider: Callable[[], TokenRuntimeConfig],
) -> None:
"""由启动组合根登记令牌安全配置快照工厂。"""
global _token_runtime_config_provider
_token_runtime_config_provider = provider
def get_token_runtime_config() -> TokenRuntimeConfig:
"""返回当前令牌编解码使用的不可变配置快照。"""
if _token_runtime_config_provider is None:
raise RuntimeError("令牌运行时配置尚未装配")
return _token_runtime_config_provider()
def configure_runtime_configuration(configuration: RuntimeConfiguration) -> None:
"""由启动组合根登记各运行面使用的类型化配置快照工厂。"""
global _runtime_configuration