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

Function ExtractConnectionDetails

connection.go:36–62  ·  view source on GitHub ↗

ExtractConnectionDetails extracts XR connection details from the supplied composed resource. If no ExtractConfigs are supplied no connection details will be returned.

(cd xpresource.Composed, data managed.ConnectionDetails, cfgs ...v1beta1.ConnectionDetail)

Source from the content-addressed store, hash-verified

34// composed resource. If no ExtractConfigs are supplied no connection details
35// will be returned.
36func ExtractConnectionDetails(cd xpresource.Composed, data managed.ConnectionDetails, cfgs ...v1beta1.ConnectionDetail) (managed.ConnectionDetails, error) {
37 out := map[string][]byte{}
38 for _, cfg := range cfgs {
39 if err := ValidateConnectionDetail(cfg); err != nil {
40 return nil, errors.Wrap(err, "invalid")
41 }
42 switch cfg.Type {
43 case v1beta1.ConnectionDetailTypeFromValue:
44 out[cfg.Name] = []byte(*cfg.Value)
45 case v1beta1.ConnectionDetailTypeFromConnectionSecretKey:
46 if data[*cfg.FromConnectionSecretKey] == nil {
47 // We don't consider this an error because it's possible the
48 // key will still be written at some point in the future.
49 continue
50 }
51 out[cfg.Name] = data[*cfg.FromConnectionSecretKey]
52 case v1beta1.ConnectionDetailTypeFromFieldPath:
53 // Note we're checking that the error _is_ nil. If we hit an error
54 // we silently avoid including this connection secret. It's possible
55 // the path will start existing with a valid value in future.
56 if b, err := fromFieldPath(cd, *cfg.FromFieldPath); err == nil {
57 out[cfg.Name] = b
58 }
59 }
60 }
61 return out, nil
62}
63
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.

Callers 2

RunFunctionMethod · 0.85

Calls 2

ValidateConnectionDetailFunction · 0.85
fromFieldPathFunction · 0.85

Tested by 1