crossplane-function-sdk-python 0.4.0__py3-none-any.whl → 0.6.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 +39 -4
- {crossplane_function_sdk_python-0.4.0.dist-info → crossplane_function_sdk_python-0.6.0.dist-info}/METADATA +7 -6
- {crossplane_function_sdk_python-0.4.0.dist-info → crossplane_function_sdk_python-0.6.0.dist-info}/RECORD +6 -6
- {crossplane_function_sdk_python-0.4.0.dist-info → crossplane_function_sdk_python-0.6.0.dist-info}/WHEEL +1 -1
- {crossplane_function_sdk_python-0.4.0.dist-info → crossplane_function_sdk_python-0.6.0.dist-info}/licenses/LICENSE +0 -0
crossplane/function/resource.py
CHANGED
|
@@ -17,12 +17,47 @@
|
|
|
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
|
+
data = source.model_dump(exclude_defaults=True, warnings=False)
|
|
42
|
+
# In Pydantic, exclude_defaults=True in model_dump excludes fields
|
|
43
|
+
# that have their value equal to the default. If a field like
|
|
44
|
+
# apiVersion is set to its default value 's3.aws.upbound.io/v1beta2'
|
|
45
|
+
# (and not explicitly provided during initialization), it will be
|
|
46
|
+
# excluded from the serialized output.
|
|
47
|
+
data['apiVersion'] = source.apiVersion
|
|
48
|
+
data['kind'] = source.kind
|
|
49
|
+
r.resource.update(data)
|
|
50
|
+
case structpb.Struct():
|
|
51
|
+
# TODO(negz): Use struct_to_dict and update to match other semantics?
|
|
52
|
+
r.resource.MergeFrom(source)
|
|
53
|
+
case dict():
|
|
54
|
+
r.resource.update(source)
|
|
55
|
+
case _:
|
|
56
|
+
t = type(source)
|
|
57
|
+
msg = f"Unsupported type: {t}"
|
|
58
|
+
raise TypeError(msg)
|
|
59
|
+
|
|
60
|
+
|
|
26
61
|
def dict_to_struct(d: dict) -> structpb.Struct:
|
|
27
62
|
"""Create a Struct well-known type from the supplied dict.
|
|
28
63
|
|
|
@@ -83,10 +118,10 @@ def get_condition(resource: structpb.Struct, typ: str) -> Condition:
|
|
|
83
118
|
"""
|
|
84
119
|
unknown = Condition(typ=typ, status="Unknown")
|
|
85
120
|
|
|
86
|
-
if "status" not in resource:
|
|
121
|
+
if not resource or "status" not in resource:
|
|
87
122
|
return unknown
|
|
88
123
|
|
|
89
|
-
if "conditions" not in resource["status"]:
|
|
124
|
+
if not resource["status"] or "conditions" not in resource["status"]:
|
|
90
125
|
return unknown
|
|
91
126
|
|
|
92
127
|
for c in resource["status"]["conditions"]:
|
|
@@ -122,9 +157,9 @@ class Credentials:
|
|
|
122
157
|
def get_credentials(req: structpb.Struct, name: str) -> Credentials:
|
|
123
158
|
"""Get the supplied credentials."""
|
|
124
159
|
empty = Credentials(type="data", data={})
|
|
125
|
-
if "credentials" not in req:
|
|
160
|
+
if not req or "credentials" not in req:
|
|
126
161
|
return empty
|
|
127
|
-
if name not in req["credentials"]:
|
|
162
|
+
if not req["credentials"] or name not in req["credentials"]:
|
|
128
163
|
return empty
|
|
129
164
|
return Credentials(
|
|
130
165
|
type=req["credentials"][name]["type"],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: crossplane-function-sdk-python
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.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
|
|
@@ -14,7 +14,8 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
14
14
|
Requires-Python: >=3.11
|
|
15
15
|
Requires-Dist: grpcio-reflection==1.*
|
|
16
16
|
Requires-Dist: grpcio==1.*
|
|
17
|
-
Requires-Dist: protobuf==5.
|
|
17
|
+
Requires-Dist: protobuf==5.29.3
|
|
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=DtYXkdzOSFDLCo0rG7l_tz5EZeXg-UK3VURBigcLQSg,704
|
|
2
2
|
crossplane/function/logging.py,sha256=Zawqq36FBzjkVg4bJ3VGK12-so7N8yAMoSPrhdwpBSA,2503
|
|
3
|
-
crossplane/function/resource.py,sha256=
|
|
3
|
+
crossplane/function/resource.py,sha256=NT8Z1dt3Tz82P9q9bqXrR8HwohtYWJaG3AnvN7C3E1w,5502
|
|
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.6.0.dist-info/METADATA,sha256=qPkiww0PHZ0LLfT-BqZ52t2ZUPVVwap83nDy0ABhQD8,3212
|
|
15
|
+
crossplane_function_sdk_python-0.6.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
16
|
+
crossplane_function_sdk_python-0.6.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
17
|
+
crossplane_function_sdk_python-0.6.0.dist-info/RECORD,,
|
|
File without changes
|