MCPcopy
hub / github.com/getsops/sops / treeBranchFromJSON

Method treeBranchFromJSON

stores/json/store.go:280–302  ·  view source on GitHub ↗
(in []byte)

Source from the content-addressed store, hash-verified

278}
279
280func (store Store) treeBranchFromJSON(in []byte) (sops.TreeBranch, error) {
281 dec := json.NewDecoder(bytes.NewReader(in))
282 // Decode numbers as json.Number instead of the default float64, then
283 // normalize each to int/float64 (see normalizeJSONNumber). The default
284 // float64 silently loses precision for integers larger than 2^53.
285 dec.UseNumber()
286 value, err := dec.Token()
287 if err != nil {
288 return nil, err
289 }
290 if delim, ok := value.(json.Delim); ok {
291 if delim.String() != "{" {
292 return nil, fmt.Errorf("SOPS only supports JSON files with a top-level object (starting with '{'), not arrays or other types. Got delimiter %s instead. To encrypt this file, wrap it in an object, e.g., {\"data\": [...]}", value)
293 }
294 } else {
295 v, nerr := normalizeJSONNumber(value)
296 if nerr != nil {
297 v = value
298 }
299 return nil, fmt.Errorf("SOPS only supports JSON files with a top-level object (starting with '{'), not other JSON types. Got %#v of type %T instead", v, v)
300 }
301 return store.treeBranchFromJSONDecoder(dec)
302}
303
304func (store Store) reindentJSON(in []byte) ([]byte, error) {
305 var out bytes.Buffer

Callers 14

LoadPlainFileMethod · 0.95
TestIntegerBoundariesFunction · 0.95
TestDecodeJSONFunction · 0.80
TestDecodeNumberFunction · 0.80
TestDecodeArrayFunction · 0.80
TestDecodeEmptyFunction · 0.80
TestDecodeJSONWithArrayFunction · 0.80

Implementers 5

Storestores/dotenv/store.go
Storestores/ini/store.go
Storestores/yaml/store.go
Storestores/json/store.go
BinaryStorestores/json/store.go

Calls 3

normalizeJSONNumberFunction · 0.85
StringMethod · 0.45

Tested by 13

TestIntegerBoundariesFunction · 0.76
TestDecodeJSONFunction · 0.64
TestDecodeNumberFunction · 0.64
TestDecodeArrayFunction · 0.64
TestDecodeEmptyFunction · 0.64
TestDecodeJSONWithArrayFunction · 0.64
TestEncodeSimpleJSONFunction · 0.64