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

オープン
#557 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@BlueLabelscotch がすでに取り組んでいます。

2026年11月29日 から。

  • #573 @BlueLabelscotch による — オープン
  • #574 @BlueLabelscotch による — オープン

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
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時間
マージ済み PR(30日)
111

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

harness/cli のほかの issue

harness/cli の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。