crossplane-function-sdk-python 0.3.0__py3-none-any.whl → 0.4.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.
@@ -20,11 +20,14 @@ import os
20
20
  import grpc
21
21
  from grpc_reflection.v1alpha import reflection
22
22
 
23
+ import crossplane.function.proto.v1.run_function_pb2 as fnv1
24
+ import crossplane.function.proto.v1.run_function_pb2_grpc as grpcv1
23
25
  import crossplane.function.proto.v1beta1.run_function_pb2 as fnv1beta1
24
26
  import crossplane.function.proto.v1beta1.run_function_pb2_grpc as grpcv1beta1
25
27
 
26
28
  SERVICE_NAMES = (
27
29
  reflection.SERVICE_NAME,
30
+ fnv1.DESCRIPTOR.services_by_name["FunctionRunnerService"].full_name,
28
31
  fnv1beta1.DESCRIPTOR.services_by_name["FunctionRunnerService"].full_name,
29
32
  )
30
33
 
@@ -62,7 +65,7 @@ def load_credentials(tls_certs_dir: str) -> grpc.ServerCredentials:
62
65
 
63
66
 
64
67
  def serve(
65
- function: grpcv1beta1.FunctionRunnerService,
68
+ function: grpcv1.FunctionRunnerService,
66
69
  address: str,
67
70
  *,
68
71
  creds: grpc.ServerCredentials,
@@ -87,7 +90,10 @@ def serve(
87
90
 
88
91
  server = grpc.aio.server()
89
92
 
90
- grpcv1beta1.add_FunctionRunnerServiceServicer_to_server(function, server)
93
+ grpcv1.add_FunctionRunnerServiceServicer_to_server(function, server)
94
+ grpcv1beta1.add_FunctionRunnerServiceServicer_to_server(
95
+ BetaFunctionRunner(wrapped=function), server
96
+ )
91
97
  reflection.enable_server_reflection(SERVICE_NAMES, server)
92
98
 
93
99
  if creds is None and insecure is False:
@@ -112,3 +118,30 @@ def serve(
112
118
  finally:
113
119
  loop.run_until_complete(server.stop(grace=5))
114
120
  loop.close()
121
+
122
+
123
+ class BetaFunctionRunner(grpcv1beta1.FunctionRunnerService):
124
+ """A BetaFunctionRunner handles beta gRPC RunFunctionRequests.
125
+
126
+ It handles requests by passing them to a wrapped v1.FunctionRunnerService.
127
+ Incoming v1beta1 requests are converted to v1 by round-tripping them through
128
+ serialization. Outgoing requests are converted from v1 to v1beta1 the same
129
+ way.
130
+ """
131
+
132
+ def __init__(self, wrapped: grpcv1.FunctionRunnerService):
133
+ """Create a new BetaFunctionRunner."""
134
+ self.wrapped = wrapped
135
+
136
+ async def RunFunction( # noqa: N802 # gRPC requires this name.
137
+ self, req: fnv1beta1.RunFunctionRequest, context: grpc.aio.ServicerContext
138
+ ) -> fnv1beta1.RunFunctionResponse:
139
+ """Run the underlying function."""
140
+ gareq = fnv1.RunFunctionRequest()
141
+ gareq.ParseFromString(req.SerializeToString())
142
+
143
+ garsp = await self.wrapped.RunFunction(gareq, context)
144
+ rsp = fnv1beta1.RunFunctionResponse()
145
+ rsp.ParseFromString(garsp.SerializeToString())
146
+
147
+ return rsp
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: crossplane-function-sdk-python
3
- Version: 0.3.0
3
+ Version: 0.4.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,6 +14,7 @@ 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.27.2
17
18
  Requires-Dist: structlog==24.*
18
19
  Description-Content-Type: text/markdown
19
20
 
@@ -0,0 +1,17 @@
1
+ crossplane/function/__version__.py,sha256=UmYGftOClDeeEqm_1NAJL-F44l3lUDF3p6gNQUY3O6E,704
2
+ crossplane/function/logging.py,sha256=Zawqq36FBzjkVg4bJ3VGK12-so7N8yAMoSPrhdwpBSA,2503
3
+ crossplane/function/resource.py,sha256=wsPYkPKjO63Gz2HNyHoE2fe-TGXmFg0MjAborujymIA,3861
4
+ crossplane/function/response.py,sha256=5TDz2vXcvH2cMuDojN1YFrr0Vsyvz1XCzNEBwxruFf4,2354
5
+ crossplane/function/runtime.py,sha256=DoCLFildkwBgB-y-qlHcoSXStDRcJ426_V81C3QvVOE,4864
6
+ crossplane/function/proto/v1/run_function.proto,sha256=83RIkEQWuMfXC5HPaPpJqXXDxYMR3VlG4xhmtutle5k,12032
7
+ crossplane/function/proto/v1/run_function_pb2.py,sha256=DFKnyLgxtXMcwftED4BF6yU9D1Wd7vlKq-GSThbzwc0,10732
8
+ crossplane/function/proto/v1/run_function_pb2.pyi,sha256=IYcl0F9Chx_jN6AP9FI0yZCqidpbiFCK0ANU6AlKfXY,10624
9
+ crossplane/function/proto/v1/run_function_pb2_grpc.py,sha256=plSu4zbwx7I-0vRe0u4UKrRMQgP8m0o4zj7DD9FeBkk,4017
10
+ crossplane/function/proto/v1beta1/run_function.proto,sha256=xep0DvulCjo8LUf-2fObjsxnDlRD-wCmjWeBV4gVonU,12155
11
+ crossplane/function/proto/v1beta1/run_function_pb2.py,sha256=LmKTg848G5Ud8GI2AIK2jjLj19nnjthRsQwECZgE4ls,10907
12
+ crossplane/function/proto/v1beta1/run_function_pb2.pyi,sha256=IYcl0F9Chx_jN6AP9FI0yZCqidpbiFCK0ANU6AlKfXY,10624
13
+ crossplane/function/proto/v1beta1/run_function_pb2_grpc.py,sha256=Abx0c4U82vIsWyeIKwS1vfEshP74N6gjB-hx0DM1lFk,4082
14
+ crossplane_function_sdk_python-0.4.0.dist-info/METADATA,sha256=VS0q5hBjxru_-tiQyLIMbPI6fKCYPl_Mx34YsBWhsnI,3192
15
+ crossplane_function_sdk_python-0.4.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
16
+ crossplane_function_sdk_python-0.4.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
17
+ crossplane_function_sdk_python-0.4.0.dist-info/RECORD,,
@@ -1,13 +0,0 @@
1
- crossplane/function/__version__.py,sha256=tqA7NsKI87Qs9KuV6_27-GU8EBOe0-jcyYictk-vtqM,704
2
- crossplane/function/logging.py,sha256=Zawqq36FBzjkVg4bJ3VGK12-so7N8yAMoSPrhdwpBSA,2503
3
- crossplane/function/resource.py,sha256=41u-aZ6TZB0cBMMU8JABPR0PSqevLJLh_rWvXOkbn1c,3759
4
- crossplane/function/response.py,sha256=fYJcPz5ZVN06hbNWXzy0tBTOMHNYQvj3m9JjWb2qRU8,2429
5
- crossplane/function/runtime.py,sha256=7-fWdxK__vbEjy6jQTnoYxtCa_bax50-qJXZP5Fz3nM,3505
6
- crossplane/function/proto/v1beta1/run_function.proto,sha256=hDZgaavZ_NAAZH0OBDMJjGKpUCptQeFORviIqVXO_tA,9841
7
- crossplane/function/proto/v1beta1/run_function_pb2.py,sha256=wVTF4w88n6TYgmZvVHE_AcB06HtHGqmCsOxH_fW9guI,9136
8
- crossplane/function/proto/v1beta1/run_function_pb2.pyi,sha256=xitztFrrlLvArYum_uaNV_WZNGjcb8FT0hdHOx6K3e0,8901
9
- crossplane/function/proto/v1beta1/run_function_pb2_grpc.py,sha256=iLQTF8CHQzjZlBGJUJTWPTfNSmm3ew02zGf6OPIsxVY,3026
10
- crossplane_function_sdk_python-0.3.0.dist-info/METADATA,sha256=JmN799wI7T6k3oxFWoPAS46ywnfEKDLsTnsJEvI7U48,3160
11
- crossplane_function_sdk_python-0.3.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
12
- crossplane_function_sdk_python-0.3.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
13
- crossplane_function_sdk_python-0.3.0.dist-info/RECORD,,