crossplane-function-sdk-python 0.4.0__py3-none-any.whl → 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- crossplane/function/__version__.py +1 -1
- crossplane/function/resource.py +27 -0
- {crossplane_function_sdk_python-0.4.0.dist-info → crossplane_function_sdk_python-0.5.0.dist-info}/METADATA +5 -4
- {crossplane_function_sdk_python-0.4.0.dist-info → crossplane_function_sdk_python-0.5.0.dist-info}/RECORD +6 -6
- {crossplane_function_sdk_python-0.4.0.dist-info → crossplane_function_sdk_python-0.5.0.dist-info}/WHEEL +0 -0
- {crossplane_function_sdk_python-0.4.0.dist-info → crossplane_function_sdk_python-0.5.0.dist-info}/licenses/LICENSE +0 -0
crossplane/function/resource.py
CHANGED
|
@@ -17,12 +17,39 @@
|
|
|
17
17
|
import dataclasses
|
|
18
18
|
import datetime
|
|
19
19
|
|
|
20
|
+
import pydantic
|
|
20
21
|
from google.protobuf import struct_pb2 as structpb
|
|
21
22
|
|
|
23
|
+
import crossplane.function.proto.v1.run_function_pb2 as fnv1
|
|
24
|
+
|
|
22
25
|
# TODO(negz): Do we really need dict_to_struct and struct_to_dict? They don't do
|
|
23
26
|
# much, but are perhaps useful for discoverability/"documentation" purposes.
|
|
24
27
|
|
|
25
28
|
|
|
29
|
+
def update(r: fnv1.Resource, source: dict | structpb.Struct | pydantic.BaseModel):
|
|
30
|
+
"""Update a composite or composed resource.
|
|
31
|
+
|
|
32
|
+
Use update to add or update the supplied resource. If the resource doesn't
|
|
33
|
+
exist, it'll be added. If the resource does exist, it'll be updated. The
|
|
34
|
+
update method semantics are the same as a dictionary's update method. Fields
|
|
35
|
+
that don't exist will be added. Fields that exist will be overwritten.
|
|
36
|
+
|
|
37
|
+
The source can be a dictionary, a protobuf Struct, or a Pydantic model.
|
|
38
|
+
"""
|
|
39
|
+
match source:
|
|
40
|
+
case pydantic.BaseModel():
|
|
41
|
+
r.resource.update(source.model_dump(exclude_defaults=True, warnings=False))
|
|
42
|
+
case structpb.Struct():
|
|
43
|
+
# TODO(negz): Use struct_to_dict and update to match other semantics?
|
|
44
|
+
r.resource.MergeFrom(source)
|
|
45
|
+
case dict():
|
|
46
|
+
r.resource.update(source)
|
|
47
|
+
case _:
|
|
48
|
+
t = type(source)
|
|
49
|
+
msg = f"Unsupported type: {t}"
|
|
50
|
+
raise TypeError(msg)
|
|
51
|
+
|
|
52
|
+
|
|
26
53
|
def dict_to_struct(d: dict) -> structpb.Struct:
|
|
27
54
|
"""Create a Struct well-known type from the supplied dict.
|
|
28
55
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: crossplane-function-sdk-python
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: The Python SDK for Crossplane composition functions
|
|
5
5
|
Project-URL: Documentation, https://github.com/crossplane/function-sdk-python#readme
|
|
6
6
|
Project-URL: Issues, https://github.com/crossplane/function-sdk-python/issues
|
|
@@ -15,6 +15,7 @@ Requires-Python: >=3.11
|
|
|
15
15
|
Requires-Dist: grpcio-reflection==1.*
|
|
16
16
|
Requires-Dist: grpcio==1.*
|
|
17
17
|
Requires-Dist: protobuf==5.27.2
|
|
18
|
+
Requires-Dist: pydantic==2.*
|
|
18
19
|
Requires-Dist: structlog==24.*
|
|
19
20
|
Description-Content-Type: text/markdown
|
|
20
21
|
|
|
@@ -54,11 +55,11 @@ Some useful commands:
|
|
|
54
55
|
# Generate gRPC stubs.
|
|
55
56
|
hatch run generate:protoc
|
|
56
57
|
|
|
57
|
-
#
|
|
58
|
-
hatch
|
|
58
|
+
# Format and lint the code.
|
|
59
|
+
hatch fmt
|
|
59
60
|
|
|
60
61
|
# Run unit tests.
|
|
61
|
-
hatch
|
|
62
|
+
hatch test
|
|
62
63
|
|
|
63
64
|
# Build an sdist and wheel.
|
|
64
65
|
hatch build
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
crossplane/function/__version__.py,sha256=
|
|
1
|
+
crossplane/function/__version__.py,sha256=EpOLy6RQc6F3rnJZbtuQ57CcZ6WoDo9E8EbbFaW0a8Y,704
|
|
2
2
|
crossplane/function/logging.py,sha256=Zawqq36FBzjkVg4bJ3VGK12-so7N8yAMoSPrhdwpBSA,2503
|
|
3
|
-
crossplane/function/resource.py,sha256=
|
|
3
|
+
crossplane/function/resource.py,sha256=Nv_ARRqhMheoGAErKPsty5unyn3P2TOvHM-UVBM6RPY,4946
|
|
4
4
|
crossplane/function/response.py,sha256=5TDz2vXcvH2cMuDojN1YFrr0Vsyvz1XCzNEBwxruFf4,2354
|
|
5
5
|
crossplane/function/runtime.py,sha256=DoCLFildkwBgB-y-qlHcoSXStDRcJ426_V81C3QvVOE,4864
|
|
6
6
|
crossplane/function/proto/v1/run_function.proto,sha256=83RIkEQWuMfXC5HPaPpJqXXDxYMR3VlG4xhmtutle5k,12032
|
|
@@ -11,7 +11,7 @@ crossplane/function/proto/v1beta1/run_function.proto,sha256=xep0DvulCjo8LUf-2fOb
|
|
|
11
11
|
crossplane/function/proto/v1beta1/run_function_pb2.py,sha256=LmKTg848G5Ud8GI2AIK2jjLj19nnjthRsQwECZgE4ls,10907
|
|
12
12
|
crossplane/function/proto/v1beta1/run_function_pb2.pyi,sha256=IYcl0F9Chx_jN6AP9FI0yZCqidpbiFCK0ANU6AlKfXY,10624
|
|
13
13
|
crossplane/function/proto/v1beta1/run_function_pb2_grpc.py,sha256=Abx0c4U82vIsWyeIKwS1vfEshP74N6gjB-hx0DM1lFk,4082
|
|
14
|
-
crossplane_function_sdk_python-0.
|
|
15
|
-
crossplane_function_sdk_python-0.
|
|
16
|
-
crossplane_function_sdk_python-0.
|
|
17
|
-
crossplane_function_sdk_python-0.
|
|
14
|
+
crossplane_function_sdk_python-0.5.0.dist-info/METADATA,sha256=te7cF_WoCSW0aLS5Vu5dBrwy62qaHD03psv3yXw3hME,3212
|
|
15
|
+
crossplane_function_sdk_python-0.5.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
16
|
+
crossplane_function_sdk_python-0.5.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
17
|
+
crossplane_function_sdk_python-0.5.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|