Files
hose-use/docs/modules/platform.md
T

72 lines
3.0 KiB
Markdown
Raw 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.
# Platform 模块说明(自建应用 & 工作流)
## 整体架构
```
commands/platform/ CLI 表现层
server/platform_router.py HTTP 路由层
services/platform/ 业务逻辑 & 聚合层
api/platform/ 传输层(三个 client)
```
## 三个 Client
| Client | 域名 | 用途 |
|---|---|---|
| `EkbClient` | `app.ekuaibao.com` | 拉自建应用列表 |
| `EasoClient` | `unity.ekuaibao.com` | 工作流列表 / 统计 / 配额 |
| `PiperClient` | `piper.ekuaibao.com` | 工作流详情(节点配置) |
## 认证链路
### EasoClient(unity.ekuaibao.com)四步链路
1. 主站 `accessToken` → `hose-access-token`(business-center JWT,约 30 天)
2. 主站认证 → UNITY JWT
3. UNITY JWT + hoseaccesstoken → EASO realm token(`GET /api/realms/EASO`)
4. 请求携带:`Authorization: Bearer <realm_token>` + `hoseaccesstoken: <hose_token>` + Cookie `hose-access-token`
### PiperClient(piper.ekuaibao.com)三步链路
1. 主站 `accessToken` → `hose-access-token`
2. 主站认证 → EASO JWT(`aud: EASO`,与 UNITY JWT 不同)
3. 请求携带:`Authorization: Bearer <easo_jwt>` + `platformid: <platform_id>` Header + Cookie `hose-access-token`
## 关键接口
| 接口 | 域名 | 路径 | 参数 |
|---|---|---|---|
| 自建应用列表 | app.ekuaibao.com | `GET /v2/datalink/platform/search` | `scope=enable` |
| 工作流列表 | unity.ekuaibao.com | `GET /api/easo/pipelines/logs` | `platformId`, `number`, `pageSize` |
| 工作流统计 | unity.ekuaibao.com | `GET /api/easo/stats` | `platformId` |
| 工作流配额 | unity.ekuaibao.com | `GET /api/easo/charge` | 无 |
| 工作流详情 | piper.ekuaibao.com | `GET /api/easo/pipelines/{id}` | Header: `platformid` |
## 工作流数据结构要点
- `Workflow.tasks` 是 `List[Any]`(raw dict),节点结构多态,不同类型字段不同
- 控制节点(`every` / `condition` 等)内部有 `tasks` 子列表,需要递归遍历才能找到嵌套节点
- `state=1` 为启用,`state=0` 为停用
## 服务层聚合能力
| 函数 | 说明 |
|---|---|
| `list_all_workflows` | 跨所有应用汇总,返回带 platform 信息的扁平列表 |
| `find_workflows_by_task_type` | 递归按节点类型过滤,支持 `enabled_only` |
## 待验证:全量工作流接口
**假设:** `GET /api/easo/pipelines/logs` 不传 `platformId` 时,后端可能直接返回企业下全量工作流(`platformId` 只是 UI 层的过滤参数,不是后端强制的)。
**验证方法:**
```bash
curl 'https://unity.ekuaibao.com/api/easo/pipelines/logs?number=1&pageSize=100' \
-H 'Authorization: Bearer <realm_token>' \
-H 'hoseaccesstoken: <hose_token>' \
-b 'hose-access-token=<hose_token>'
```
在浏览器 DevTools → Network 中找任意 `unity.ekuaibao.com/api/easo/` 请求即可获取上述 token。
**结论:** 本次验证未成功(会话结束前未拿到正确 token),待下次验证。若接口确实支持,可将 `list_all_workflows` 从"先拉平台列表再逐个拉工作流"改为单次请求,性能显著提升。