节点在线、应用在线、配置在线使用令牌查询
大石头 authored at 2021-12-16 19:49:30
8.32 KiB
Stardust
# 流水线 Webhook(Deployment/PipelineWebhook) > 块:发布部署 > MVC:`Stardust.Web/Areas/Deployment/Controllers/PipelineWebhookController.cs` > WebApi:`Stardust.WebApi/Areas/Deployment/Controllers/PipelineWebhookController.cs`(2026-11-04 对照:Webhook 一致+兼容路由;GetFields 为 WebApi 增强) > 盘点:2026-11-02 > **WebApi 对齐状态:✅ 已完成(2026-11-04)**——MVC 功能已全部在 WebApi 实现或已一致(缺口补齐/行为对齐/有意不补三类逐项标注);本次处理明细见 §7「2026-11-04 WebApi 补齐记录」;整体验证=dotnet build Release 0 错误 + 6681 冒烟 + McpApiTests 40/40;状态总表=Doc/MVC功能真源/WebApi对齐状态总表.md ## 1. 用户用它做什么 **无管理页,只有接口。** 控制器未标注 `[Menu(...)]`(`PipelineWebhookController.cs:15-17`);类注释说明仅有 Webhook 动作、没有管理页面,若被区域扫描成菜单会点开 404(`PipelineWebhookController.cs:10-13`)。启动时 `RemoveDeadMenus` 会删除 URL 为 `/Deployment/PipelineWebhook` 的历史死菜单(`Stardust.Web/Startup.cs:380-388`)。 Git 平台(或兼容客户端)向星尘 POST git push 类 JSON 负载,通过 URL 上的 `token` 定位流水线配置,可选 `X-Hub-Signature-256` 校验;通过后解析分支与提交信息、匹配流水线分支、防抖,创建 `AppPipelineRun` 并异步执行编译部署编排。类注释写明**无 ASP.NET 登录鉴权**,业务侧仅靠 token 与可选 secret(`PipelineWebhookController.cs:8-9`)。 视图目录 `Stardust.Web/Areas/Deployment/Views/PipelineWebhook` **不存在**,无 `.cshtml`。 ## 2. 入口与跳转 ### 页面 URL 无列表、编辑或 Cube 管理页。 ### 接口 URL | 用途 | HTTP | URL 模板 | 依据 | |------|------|----------|------| | 接收 git push webhook | POST | `/Deployment/Pipeline/Webhook?token={token}` | 路由 `[Route("[area]/Pipeline/[action]")]` + Action 名 `Webhook`(`PipelineWebhookController.cs:16-22`) | ### 谁链进来 无 UI 导航链入。调用方为外部 Git/Webhook 客户端,需自行配置 POST 目标 URL 与 query `token`。 ### 本页链出去 无(无页面)。 ## 3. 功能清单 | ID | 用户动作 | 入口 | HTTP 与路径 | 参数 | 成功时发生什么 | 失败或禁用条件 | |----|----------|------|-------------|------|----------------|----------------| | F01 | 外部系统推送代码变更 webhook | 配置的 webhook URL | POST `/Deployment/Pipeline/Webhook` | Query:`token`(必填,流水线鉴权 token,`PipelineWebhookController.cs:20-22`)。Body:原始 JSON 字符串(控制器读满 Request Body,`PipelineWebhookController.cs:27-31`)。Header:`X-Hub-Signature-256`(配置了流水线 Secret 时参与校验,`PipelineWebhookController.cs:33`、`Stardust.Web/Services/PipelineService.cs:124-127`) | HTTP 200,响应体为 JSON 对象(`Object`,非统一 ApiResponse 包装)。`token` 为空:立即 `{ result = "error", reason = "missing token" }`(`PipelineWebhookController.cs:24`)。委托 `PipelineService.HandleWebhookAsync` 后可能返回:`accepted` + `runId` + `status`(创建 Pending 的 run 并后台 `RunAsync`,`Stardust.Web/Services/PipelineService.cs:148-168`);`ignored`(`pipeline disabled` / `no branch` / `branch mismatch`,`Stardust.Web/Services/PipelineService.cs:121-135`);`skipped`(`duplicate`,同 pipeline+commit 在防抖窗口内重复,`Stardust.Web/Services/PipelineService.cs:137-139`);`error`(`invalid token` / `missing signature` / `invalid signature` / `build node unavailable` / `deploy not found`,`Stardust.Web/Services/PipelineService.cs:119-120、126-127、142-146`)。追踪:`ITracer` span `Pipeline-Webhook`(`PipelineWebhookController.cs:35-37`) | `token` 缺失见上。无效 token、流水线未启用、签名校验失败、构建节点不可用、部署不存在等见 `HandleWebhookAsync` 返回的 `result`/`reason`。Action 未标注 `[AllowAnonymous]`,若全局要求登录则未登录请求可能被框架拦截:未在源码确认 | 说明:本控制器无 `OnInsert` / `OnUpdate` / `Valid` / `Search` 及标准 Cube CRUD。 ## 4. 列表 无。 ## 5. 表单与副作用 无特殊副作用(无表单、无实体 CRUD 页)。 副作用(经 `HandleWebhookAsync`,非本控制器直接写库):匹配成功时插入 `AppPipelineRun`(`TriggerSource = "webhook"`)并异步启动 `RunAsync`(`Stardust.Web/Services/PipelineService.cs:148-166`)。具体编排步骤见 `PipelineService.RunAsync` 注释(`Stardust.Web/Services/PipelineService.cs:215-217`),本页不展开逐步明细。 ## 6. 接口一览 | Action | HTTP | 路径 | 谁可以调 | 返回 | |--------|------|------|----------|------| | `Webhook` | POST | `/Deployment/Pipeline/Webhook?token={token}` | 类注释:无登录鉴权,凭 token(+ 可选 HMAC secret)(`PipelineWebhookController.cs:8-9`);框架级匿名是否放行:未在源码确认 | JSON 对象:`{ result, reason? }` 或 `{ result, runId, status }`(见 F01 与 `Stardust.Web/Services/PipelineService.cs:115-168`) | 标准 Cube `GetPage` / `Get` / `Insert` / `Update` / `Delete`:**无**(`ControllerBase` 非实体控制器)。 ## 7. WebApi 差异 | 项 | MVC | WebApi | |----|-----|--------| | 基类 | `ControllerBase`(`PipelineWebhookController.cs:17`) | `ControllerBaseX`(`Stardust.WebApi/Areas/Deployment/Controllers/PipelineWebhookController.cs:20`) | | 默认路由模板 | `[area]/Pipeline/[action]` → POST `/Deployment/Pipeline/Webhook` | `[area]/[controller]/[action]`;`Webhook` 另加 `[Route("/Deployment/Pipeline/Webhook")]` 兼容 MVC 对外地址(`Stardust.WebApi/.../PipelineWebhookController.cs:19、25-26`) | | `Webhook` 匿名 | 未标注 `[AllowAnonymous]` | `[AllowAnonymous]`(`Stardust.WebApi/.../PipelineWebhookController.cs:26-27`) | | 额外 Action | 无 | `GetFields(ViewKinds kind)` GET,返回 token/secret 字段说明列表(`Stardust.WebApi/.../PipelineWebhookController.cs:46-60`) | **WebApi 相对 MVC 缺失的 Action:无**(MVC 仅有的 `Webhook` 在 WebApi 有对应且路径兼容)。 **WebApi 多出的 Action:`GetFields`**(MVC 无)。 `Webhook` 请求体读取、签名字段、`HandleWebhookAsync` 调用与 MVC 一致(`Stardust.WebApi/.../PipelineWebhookController.cs:29-43` 对照 `PipelineWebhookController.cs:24-38`)。 ### 2026-11-04 WebApi 补齐记录 - 对照:`Webhook` 与 MVC 一致——读满 Request Body、`X-Hub-Signature-256` 签名头、`HandleWebhookAsync` 全部结果语义(accepted/ignored/skipped/error)、缺 token 返回 `{result:"error",reason:"missing token"}`;`[AllowAnonymous]` 且保留兼容路由 `/Deployment/Pipeline/Webhook`(对外地址与 MVC 相同)。 - 结论:无缺失 Action,无需修改。 - 不补:路由模板差异(MVC `[area]/Pipeline/[action]` vs WebApi `[area]/[controller]/[action]`+显式兼容路由)——对外地址不变,保留;`GetFields` 为 WebApi 独有增强(MVC 无,不回补)。 - 验证:`dotnet build Stardust.WebApi/Stardust.WebApi.csproj -c Release --no-restore` **0 错误**(2026-11-04)。 - 差距矩阵全文:`.temp/gap/deploy.md` ## 8. 新前端必须保留 - [ ] 对外 webhook 地址仍为 POST `/Deployment/Pipeline/Webhook?token={token}`(与 MVC 路由一致) - [ ] 请求体为原始 JSON,服务端可读满 body 做 HMAC 校验 - [ ] 支持 Header `X-Hub-Signature-256`(流水线配置 Secret 非空时必填且需校验通过) - [ ] `token` 为空时返回 `{ result: "error", reason: "missing token" }` - [ ] 保留 `HandleWebhookAsync` 全部结果语义:`accepted`(含 `runId`、`status`)、`ignored`、`skipped`、`error` 及对应 `reason` 字符串 - [ ] webhook 接受后异步执行流水线,不阻塞 HTTP 响应(`Stardust.Web/Services/PipelineService.cs:163-168`) - [ ] 若新前端需要展示「如何配置 webhook URL / secret」,可参考 WebApi 的 `GetFields` 字段说明(MVC 无此接口) ## 9. 证据 - `Stardust.Web/Areas/Deployment/Controllers/PipelineWebhookController.cs` - `Stardust.Web/Services/PipelineService.cs`(`HandleWebhookAsync` 段) - `Stardust.Web/Startup.cs`(`RemoveDeadMenus`) - `Stardust.WebApi/Areas/Deployment/Controllers/PipelineWebhookController.cs` - 已确认不存在:`Stardust.Web/Areas/Deployment/Views/PipelineWebhook/` 下无任何 `.cshtml`