feat: 重命名项目为Boardware Genius并添加运行时环境同步功能
- 将项目品牌从nanobot重命名为Boardware Genius,更新所有相关文档、注释和日志输出 - 在web服务器中添加运行时环境变量同步功能,支持授权和后端身份配置 - 更新create-instance脚本以生成运行时环境文件 - 添加实例后端绑定功能到部署控制服务 - 修改入口脚本以加载运行时环境变量 - 更新前端和认证门户的相关描述文本
This commit is contained in:
@ -1 +1 @@
|
||||
"""Web interface for nanobot."""
|
||||
"""Web interface for Boardware Genius."""
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
"""FastAPI web server for nanobot frontend."""
|
||||
"""FastAPI web server for the Boardware Genius frontend."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@ -8,6 +8,7 @@ import json
|
||||
import os
|
||||
import re
|
||||
import secrets
|
||||
import shlex
|
||||
import shutil
|
||||
import time
|
||||
import zipfile
|
||||
@ -676,6 +677,8 @@ def create_app(
|
||||
|
||||
app.state.config = config
|
||||
app.state.config_path = get_config_path()
|
||||
app.state.runtime_env_path = _get_runtime_env_file_path(app.state.config_path)
|
||||
_sync_authz_runtime_env(app.state.config, app.state.runtime_env_path)
|
||||
app.state.session_manager = session_manager
|
||||
app.state.cron_service = cron_service
|
||||
app.state.bus = bus
|
||||
@ -766,6 +769,60 @@ def _get_auth_file_path() -> Path:
|
||||
return Path(__file__).resolve().parents[2] / "web_auth_users.json"
|
||||
|
||||
|
||||
_AUTHZ_RUNTIME_ENV_KEYS = (
|
||||
"NANOBOT_AUTHZ__ENABLED",
|
||||
"NANOBOT_AUTHZ__BASE_URL",
|
||||
"NANOBOT_AUTHZ__OUTLOOK_MCP_URL",
|
||||
"NANOBOT_BACKEND_IDENTITY__BACKEND_ID",
|
||||
"NANOBOT_BACKEND_IDENTITY__CLIENT_ID",
|
||||
"NANOBOT_BACKEND_IDENTITY__CLIENT_SECRET",
|
||||
"NANOBOT_BACKEND_IDENTITY__NAME",
|
||||
"NANOBOT_BACKEND_IDENTITY__PUBLIC_BASE_URL",
|
||||
)
|
||||
|
||||
|
||||
def _get_runtime_env_file_path(config_path: Path | None = None) -> Path:
|
||||
env = os.getenv("NANOBOT_RUNTIME_ENV_FILE", "").strip()
|
||||
if env:
|
||||
return Path(env).expanduser()
|
||||
base_path = config_path or get_config_path()
|
||||
return base_path.parent / "runtime.env"
|
||||
|
||||
|
||||
def _authz_runtime_env_values(config: Config) -> dict[str, str]:
|
||||
return {
|
||||
"NANOBOT_AUTHZ__ENABLED": "1" if config.authz.enabled and config.authz.base_url.strip() else "0",
|
||||
"NANOBOT_AUTHZ__BASE_URL": config.authz.base_url.strip(),
|
||||
"NANOBOT_AUTHZ__OUTLOOK_MCP_URL": config.authz.outlook_mcp_url.strip(),
|
||||
"NANOBOT_BACKEND_IDENTITY__BACKEND_ID": config.backend_identity.backend_id.strip(),
|
||||
"NANOBOT_BACKEND_IDENTITY__CLIENT_ID": config.backend_identity.client_id.strip(),
|
||||
"NANOBOT_BACKEND_IDENTITY__CLIENT_SECRET": config.backend_identity.client_secret.strip(),
|
||||
"NANOBOT_BACKEND_IDENTITY__NAME": config.backend_identity.name.strip(),
|
||||
"NANOBOT_BACKEND_IDENTITY__PUBLIC_BASE_URL": config.backend_identity.public_base_url.strip(),
|
||||
}
|
||||
|
||||
|
||||
def _sync_authz_runtime_env(config: Config, target_path: Path) -> None:
|
||||
values = _authz_runtime_env_values(config)
|
||||
target_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
lines: list[str] = []
|
||||
for key in _AUTHZ_RUNTIME_ENV_KEYS:
|
||||
value = values.get(key, "")
|
||||
if value:
|
||||
os.environ[key] = value
|
||||
lines.append(f"export {key}={shlex.quote(value)}")
|
||||
continue
|
||||
if key == "NANOBOT_AUTHZ__ENABLED":
|
||||
os.environ[key] = "0"
|
||||
lines.append("export NANOBOT_AUTHZ__ENABLED=0")
|
||||
continue
|
||||
os.environ.pop(key, None)
|
||||
lines.append(f"unset {key}")
|
||||
|
||||
target_path.write_text("\n".join(lines) + "\n", encoding="utf-8")
|
||||
|
||||
|
||||
def _load_auth_users(path: Path) -> dict[str, str]:
|
||||
"""Load users from local JSON file.
|
||||
|
||||
@ -1129,6 +1186,7 @@ def _register_routes(app: FastAPI) -> None:
|
||||
if authz_enabled:
|
||||
config.authz.enabled = True
|
||||
_save_app_config(config)
|
||||
_sync_authz_runtime_env(config, app.state.runtime_env_path)
|
||||
return _local_backend_view(config)
|
||||
|
||||
def _authz_client(config: Config):
|
||||
|
||||
Reference in New Issue
Block a user