Files
chakcy d58be74123 fix: 生成项目补齐 --encrypt/--license 构建契约(网关收集项、[license] 注入点)
- config.toml:--encrypt 会先 PyArmor 混淆 main.py / server.py,PyInstaller 静态
  分析跟不到 `from chongming.app import app`,网关包整个漏收(打包"成功"、产物
  启动报 No module named 'chongming')—— 显式列 chongming / chongming.app 等入口包;
- public/config.toml:补 [license] 段(public_key 留空),--license 的注入点;
- README.project.md:补授权公钥前置条件(keygen → license_public.key 或环境变量),
  以及 --only 对 obfuscate 同样划界(加密构建要显式带上,否则混淆被静默跳过)。
2026-10-14 15:29:25 +08:00

168 lines
5.4 KiB
TOML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
[default]
app.debug = false
app.description = "{{app_name}} — chongming 网关项目"
app.name = "{{app_name}}"
app.version = "0.1.0"
env = "development"
prefix = "/api/v1"
upload_path = "uploads"
[zenoh]
json5_path = "./config/zenoh_config.json5"
[cache]
# 单机默认 sqlite(本机共享);多实例部署改 "redis"(或共享卷 sqlite),各实例指向同一后端
backend = "sqlite"
path = "./cache_data/cache.db"
# 副本数/运行时配置的取值来源:
# "toml"(默认)= 以文件为准(启动用 config/workers/<type>/config.toml 覆盖写入缓存)
# "cache" = 以缓存为单一事实来源(管理接口改动跨重启保持)
launch_worker_count = "toml"
# redis 后端专用(backend = "redis" 时生效)
redis_host = "127.0.0.1"
redis_port = 6379
redis_db = 0
redis_password = ""
redis_prefix = "chongming:"
[security]
# 打包装备(uv run build)会自动注入随机密钥;生产环境请改用环境变量或自行替换
algorithm = "HS256"
secret_key = "your-secret-key-change-in-production"
[development]
debug = true
env = "development"
[development.server]
# 三个启动入口(serve / granian / gunicorn)共用这些参数
access_log = false
host = "0.0.0.0"
port = 8000
reload = true
[development.logging]
file = "logs"
format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
level = "DEBUG"
# access 日志采样率:0.1 = 只记录 10% 的成功请求(错误 >=400 始终全量)
access_sample_rate = 0.1
[development.cors]
allow_credentials = true
allow_headers = ["*"]
allow_methods = ["*"]
# allow_credentials=true 时 allow_origins 不能为 ["*"],需显式列出来源
allow_origins = [
"http://localhost:5173",
"http://127.0.0.1:5173",
"http://localhost:5174",
"http://127.0.0.1:5174",
]
[development.mqtt]
enabled = true
host = "127.0.0.1"
port = 1883
# true(默认)= 网关自带内嵌 amqtt Broker(开箱即用);
# false = 连接外部 Broker,host/port 改为对方地址
use_embedded_broker = true
# Broker 认证(可选,默认匿名;密码明文存放,生产建议外部 Broker + 环境变量注入)
# username = "chongming"
# password = "change-me"
[development.mqtt.broker]
# amqtt Broker 可选配置,默认允许匿名连接
# 旧式全局插件注册文件(仅作兜底兼容;新插件请在 config/workers/<type>/config.toml 各自声明)
[plugins_worker]
config_path = "./config/workers/config.toml"
[pyinstaller_build_import]
# 打包收集清单(PyInstaller --hidden-import / Nuitka --include-module),`uv run build` 的
# pack 步骤使用。网关本体(chongming-gateway 包)**未混淆时**能沿骨架的
# `from chongming.app import app` 静态跟到;但 --encrypt 会先 PyArmor 混淆
# main.py / server.py,此时静态分析跟不到,网关入口包必须显式列出(见 base 前几项)。
# 这里保留:
# - 网关入口包(chongming / chongming.app 与骨架直接引用的子模块)
# - 动态导入、静态分析看不到的(granian 内部子模块、amqtt 插件、sqlite_vfs 等)
# - public 骨架自身(server / utils)与服务器可选实现(uvloop 等)
# 内置插件专属依赖(网关本体不 import 的第三方包)写根目录 plugins_deps.toml,按插件分节声明。
base = [
"utils",
"utils.launch",
"utils.config",
"server",
# 网关入口包:--encrypt 时 main.py / server.py 先被 PyArmor 混淆,里面的
# `from chongming.app import app` 对 PyInstaller 静态分析不可见 —— 漏了会在
# 打包期"成功"、产物启动即报
# "无法导入网关(chongming.app): No module named 'chongming'"
"chongming",
"chongming.app",
"chongming.app.core.logger",
"chongming.app.core.parent_death",
"module_bank",
"granian",
"granian._compat",
"granian._futures",
"granian._granian",
"granian._imports",
"granian._internal",
"granian._loops",
"granian._signals",
"granian._types",
"granian.asgi",
"granian.constants",
"granian.errors",
"granian.http",
"granian.log",
"granian.net",
"granian.rsgi",
"granian.server",
"granian.server.common",
"granian.server.mp",
"granian.server.mt",
"granian.wsgi",
"httptools",
"uvicorn",
"sqlite_vfs",
"sqlite_vfs.core",
"sqlite_vfs.contrib",
"sqlite_vfs.contrib.fastapi_static",
"amqtt",
# amqtt 内嵌 Broker 的插件经 entry points 动态加载,静态分析看不到
"amqtt.plugins.authentication",
"amqtt.plugins.logging_amqtt",
"amqtt.plugins.sys.broker",
"amqtt.plugins.topic_checking",
# 数据库 / 缓存驱动:SQLAlchemy 与 chongming-cache 按配置动态加载,必须显式声明
"aiosqlite", # SQLite 异步驱动(网关内置 auth 库用)
"asyncpg", # PostgreSQL 驱动(插件配 database.url 时用)
"sqlmodel",
"chongming_cache.backends",
"chongming_cache.backends.sqlite_", # cache backend = "sqlite" 时使用
"chongming_worker.contracts",
"chongming_worker.route_config",
"chongming_worker.routes_publisher",
"python_multipart", # multipart 上传端点
"orjson",
"aiofiles",
]
linux = [
"uvloop",
]
windows = []
[production.module_system]
# 构建用(uv run build 的 mbank 步骤读这里):把插件源码打进 resources/plugins.mbank,
# 交付产物运行时经模块银行加载插件(网关本体是普通依赖包,不进 .mbank)
path = [
[
"resources/plugins.mbank",
"src/plugins",
"plugins",
],
]
type = "module-bank"