Files
whm bb59bb5efd fix: allow agent JWT to use attached online_db_id (Z14c)
Agent tokens use agent_id as user_id while Binding is under the human member; authorize schema/push/ensure against the agent's mounted OnlineDBID.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-05 18:22:57 +08:00
..

Platformgo-zero骨架

Publish校验蓝图 → 分配 schema → 生成/执行 DDL → 注册元数据)+ 动态 CRUD + JWT。

目录

platform/
  platform.go
  docker-compose.yml          # 本地 Postgres
  etc/platform.yaml
  internal/
    authx/                    # JWT 签发/校验 + Dev 头兜底
    blueprint/
    schema/                   # Postgres DDL数值 PK 用 IDENTITY
    meta/
    crud/                     # MemoryEngine + PostgresEngine
    logic/applogic/
    handler/

运行(内存 + JWT

cd platform
go test ./...
go run . -f etc/platform.yaml
# 另开终端
go run ./scripts/smoke.go

冒烟会:签发 JWT → publish → create → list → 非法 token 应 401。

运行Postgres 行级 Engine

docker compose up -d

etc/platform.yaml

DataSource: "postgres://platform:platform@127.0.0.1:5432/platform?sslmode=disable"
DevAuth: false

再启动服务。此时:

  • publish 真实建 schema/表
  • CRUD 走 PostgresEngine(参数化 SQL + tenant_id 强制条件)

JWT

POST /api/v1/auth/token
{"tenant_id":1,"user_id":1,"secret":"dev-only-change-me"}

→ {"access_token":"...","token_type":"Bearer","expires_at":...}

业务请求:

Authorization: Bearer <access_token>
配置 行为
DevAuth: false 必须带合法 JWT
DevAuth: true 无 JWT 时可用 X-Tenant-Id / X-User-Id(仅本地)
带了错误 Bearer 一律 401即使 DevAuth=true

生产请更换 Auth.AccessSecret / IssueSecret,并关掉 DevAuth

元数据落库

启用 DataSource 后自动迁移并使用 platform_meta.tenant_apps

  • 存 blueprint / ddl / endpoints / status
  • 进程重启后仍可按 slug 解析动态 CRUD
  • 无库时回退内存 MemoryStore