MCPcopy Create free account
hub / github.com/crossplane-contrib/function-patch-and-transform / fromFieldPath

Function fromFieldPath

connection.go:66–83  ·  view source on GitHub ↗

fromFieldPath tries to read the value from the supplied field path first as a plain string. If this fails, it falls back to reading it as JSON.

(from runtime.Object, path string)

Source from the content-addressed store, hash-verified

64// fromFieldPath tries to read the value from the supplied field path first as a
65// plain string. If this fails, it falls back to reading it as JSON.
66func fromFieldPath(from runtime.Object, path string) ([]byte, error) {
67 fromMap, err := runtime.DefaultUnstructuredConverter.ToUnstructured(from)
68 if err != nil {
69 return nil, err
70 }
71
72 str, err := fieldpath.Pave(fromMap).GetString(path)
73 if err == nil {
74 return []byte(str), nil
75 }
76
77 in, err := fieldpath.Pave(fromMap).GetValue(path)
78 if err != nil {
79 return nil, err
80 }
81
82 return json.Marshal(in)
83}
84
85// supportsConnectionDetails determines if the given XR supports native/classic
86// connection details.

Callers 1

ExtractConnectionDetailsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected