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

Function contextWithEnvironment

fn_test.go:1558–1569  ·  view source on GitHub ↗

Crossplane sends as context a fake resource: { "apiVersion": "internal.crossplane.io/v1alpha1", "kind": "Environment", ... the actual environment content ... } See: https://github.com/crossplane/crossplane/blob/806f0d20d146f6f4f1735c5ec6a7dc78923814b3/internal/controller/apiextensions/composite/envi

(data map[string]any)

Source from the content-addressed store, hash-verified

1556// runtime.DefaultUnstructuredConverter.FromUnstructured to convert it back to
1557// an object.
1558func contextWithEnvironment(data map[string]any) *structpb.Struct {
1559 if data == nil {
1560 data = map[string]any{}
1561 }
1562 u := unstructured.Unstructured{Object: data}
1563 u.SetGroupVersionKind(internalEnvironmentGVK)
1564 d, err := structpb.NewStruct(u.UnstructuredContent())
1565 if err != nil {
1566 panic(err)
1567 }
1568 return &structpb.Struct{Fields: map[string]*structpb.Value{fncontext.KeyEnvironment: structpb.NewStructValue(d)}}
1569}

Callers 1

TestRunFunctionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected