Help us shape the future of Go! Take the 2026 Go Developer Survey

bodyinput

package
v1.35.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package bodyinput decodes a request body supplied as a file, accepting either JSON or YAML.

It exists so the Platform and Security Cloud commands accept the same input formats the Pro generated commands do. The Pro template carries its own copy (normalizeInputToJSON in generator/parser/generator.go's registryTemplate) because generated code stands alone; these two products share this one, so the fallback ladder cannot drift between them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Normalize

func Normalize(raw []byte) (any, error)

Normalize decodes raw as JSON, falling back to YAML, and returns a value built from JSON-native types only (map[string]any, []any, string, float64, bool). YAML input is round-tripped through JSON rather than returned as yaml.v3 decoded it, because yaml.v3 produces types encoding/json refuses to marshal — a mapping with non-string keys decodes to map[any]any, and a timestamp scalar to time.Time. Returning those would move the failure from here to whichever transport marshals the body, where it reads as an internal error rather than as a malformed input file.

The round trip alone cannot do that job, which is the trap this once fell into: json.Marshal is the call that refuses map[any]any, so handing it the value straight turned the two shapes it exists to fix into "re-marshaling YAML as JSON: json: unsupported ..." — the malformed-input error, for a perfectly good YAML file. jsonSafe converts them first and the round trip then only settles number types.

What json.Marshal refuses has moved: Go 1.26 rejects any map[any]any, while 1.27 spells an *integer* key and still rejects a boolean, float or null one ("object member name must be a string"). YAML permits all four, so the walker is still doing work on the current toolchain — and the test pins the resulting shapes rather than an error string, since which keys fail is a moving target.

Input carrying no content is an error rather than a nil body. A nil body means "send no body" to every caller here, so an empty file, a file of YAML comments, or a literal null would otherwise make a write that sent nothing indistinguishable from one that was never given a --from-file at all.

func RefuseCredentialSets added in v1.32.0

func RefuseCredentialSets(sets []string, credentialPaths []string) error

RefuseCredentialSets returns an error for the first --set pair that would put a credential on the command line, where it lands in shell history, ps output and CI logs. credentialPaths are the dotted body paths the generator found to carry a secret, with "[]" for an array element. A pair is refused when its key is one of them, or when its value is a JSON object or array that carries one, since `--set deviceSyncAuth='{"clientSecret":"…"}'` exposes the secret just the same. The value is decoded whatever its first byte, so leading whitespace cannot hide one. Paths are compared in canonical form (canonicalSetPath), and a key no canonical form can safely match is refused outright.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL