Add a pre-send request payload hook (client and spec level)

未关闭
#557 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@BlueLabelscotch 已经在做这个了。

开始于 2026年11月29日。

  • #573 来自 @BlueLabelscotch —— 未关闭
  • #574 来自 @BlueLabelscotch —— 未关闭

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
go

调研方向

Start by reading client.Request, DoRequest, and buildRequest to trace how request bodies are assembled, serialized, and shown by --preview-request; also read docs/mutation.md for the existing update_body_pick behavior. Define the hook and spec key after resolving the open questions about the expression signature and query parameters. Done means the JSON round-trip and error handling are covered, and the transformed payload is used before sending.

由索引模型根据 Issue 内容生成。

描述

enhancement

Problem

Some APIs reject the body we build, and the spec has no way to fix it up just before the request goes out. Example, GitOps repo credential update: the GET returns connectionState.attemptedAt as a string, but PUT expects {seconds, nanos}, so a get-then-put round trip fails with a 400. The UI avoids this by sending only writable fields plus an updateMask.

Today the options are hand-picking every field in update_body_pick (silently drops new API fields, see docs/mutation.md) or special-casing it in core.

Proposed design

1. Low-level hook in the client. client.Request gets an optional payload function that runs immediately before the body is serialized and sent:

type Request struct {
    ...
    BodyFn func(body any) (any, error)
}
  • DoRequest applies it after buildRequest assembles the body, so every caller (get-then-put, create, execute) can use it.
  • The body is round-tripped through JSON (marshal, then unmarshal into a generic Go value) before the function runs, so the function always edits a plain map[string]any regardless of how the body was built.
  • --preview-request shows the transformed body.

2. Spec-level declaration. A spec key on the endpoint (name TBD, e.g. body_transform) takes an expr function that is wired to the hook, so a noun can fix its own payload without Go changes, e.g. convert attemptedAt to {seconds, nanos} or derive updateMask from the keys changed by --set.

Scope

  • Core change first (client hook plus spec key); adopting it for gitops_repocred is a separate module PR.
  • No tests for the framework passing the function through; cover the JSON round-trip and error handling.

Open questions

  • Name of the spec key and the expr function signature.
  • Whether the same hook should also be able to rewrite query params (see #527).
  • Whether to also raise the attemptedAt read/write mismatch as a server-side issue.

Related: #527, #509.

主要语言
Go
星标
29
派生
24
平均合并
1 天 9 小时
30 天内合并 PR
111

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

harness/cli 的其他 Issue

查看 harness/cli 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。