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

Abierto
#557 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@BlueLabelscotch ya está trabajando en esto.

Desde el 29/11/2026.

  • #573 de @BlueLabelscotch — abierto
  • #574 de @BlueLabelscotch — abierto

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
go

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Go
Estrellas
29
Forks
24
Merge medio
1 d 9 h
PR fusionados (30 d)
111

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de harness/cli

Todos los issues de harness/cli

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.