crossplane-function-sdk-python 0.2.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.
@@ -18,16 +18,16 @@ import datetime
18
18
 
19
19
  from google.protobuf import duration_pb2 as durationpb
20
20
 
21
- import crossplane.function.proto.v1beta1.run_function_pb2 as fnv1beta1
21
+ import crossplane.function.proto.v1.run_function_pb2 as fnv1
22
22
 
23
23
  """The default TTL for which a RunFunctionResponse may be cached."""
24
24
  DEFAULT_TTL = datetime.timedelta(minutes=1)
25
25
 
26
26
 
27
27
  def to(
28
- req: fnv1beta1.RunFunctionRequest,
28
+ req: fnv1.RunFunctionRequest,
29
29
  ttl: datetime.timedelta = DEFAULT_TTL,
30
- ) -> fnv1beta1.RunFunctionResponse:
30
+ ) -> fnv1.RunFunctionResponse:
31
31
  """Create a response to the supplied request.
32
32
 
33
33
  Args:
@@ -42,38 +42,38 @@ def to(
42
42
  """
43
43
  dttl = durationpb.Duration()
44
44
  dttl.FromTimedelta(ttl)
45
- return fnv1beta1.RunFunctionResponse(
46
- meta=fnv1beta1.ResponseMeta(tag=req.meta.tag, ttl=dttl),
45
+ return fnv1.RunFunctionResponse(
46
+ meta=fnv1.ResponseMeta(tag=req.meta.tag, ttl=dttl),
47
47
  desired=req.desired,
48
48
  context=req.context,
49
49
  )
50
50
 
51
51
 
52
- def normal(rsp: fnv1beta1.RunFunctionResponse, message: str) -> None:
52
+ def normal(rsp: fnv1.RunFunctionResponse, message: str) -> None:
53
53
  """Add a normal result to the response."""
54
54
  rsp.results.append(
55
- fnv1beta1.Result(
56
- severity=fnv1beta1.SEVERITY_NORMAL,
55
+ fnv1.Result(
56
+ severity=fnv1.SEVERITY_NORMAL,
57
57
  message=message,
58
58
  )
59
59
  )
60
60
 
61
61
 
62
- def warning(rsp: fnv1beta1.RunFunctionResponse, message: str) -> None:
62
+ def warning(rsp: fnv1.RunFunctionResponse, message: str) -> None:
63
63
  """Add a warning result to the response."""
64
64
  rsp.results.append(
65
- fnv1beta1.Result(
66
- severity=fnv1beta1.SEVERITY_WARNING,
65
+ fnv1.Result(
66
+ severity=fnv1.SEVERITY_WARNING,
67
67
  message=message,
68
68
  )
69
69
  )
70
70
 
71
71
 
72
- def fatal(rsp: fnv1beta1.RunFunctionResponse, message: str) -> None:
72
+ def fatal(rsp: fnv1.RunFunctionResponse, message: str) -> None:
73
73
  """Add a fatal result to the response."""
74
74
  rsp.results.append(
75
- fnv1beta1.Result(
76
- severity=fnv1beta1.SEVERITY_FATAL,
75
+ fnv1.Result(
76
+ severity=fnv1.SEVERITY_FATAL,
77
77
  message=message,
78
78
  )
79
79
  )
@@ -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,
@@ -82,9 +85,15 @@ def serve(
82
85
  If insecure is true requests will be served insecurely, even if credentials
83
86
  are supplied.
84
87
  """
88
+ # Define the loop before the server so everything uses the same loop.
89
+ loop = asyncio.get_event_loop()
90
+
85
91
  server = grpc.aio.server()
86
92
 
87
- 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
+ )
88
97
  reflection.enable_server_reflection(SERVICE_NAMES, server)
89
98
 
90
99
  if creds is None and insecure is False:
@@ -104,9 +113,35 @@ def serve(
104
113
  await server.start()
105
114
  await server.wait_for_termination()
106
115
 
107
- loop = asyncio.get_event_loop()
108
116
  try:
109
117
  loop.run_until_complete(start())
110
118
  finally:
111
119
  loop.run_until_complete(server.stop(grace=5))
112
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
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: crossplane-function-sdk-python
3
- Version: 0.2.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,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.21.1
2
+ Generator: hatchling 1.25.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,13 +0,0 @@
1
- crossplane/function/__version__.py,sha256=slI3JSn1lrsrcIeoO75cN6wfMUWyLx4d1Utz2L4MeQ4,704
2
- crossplane/function/logging.py,sha256=Zawqq36FBzjkVg4bJ3VGK12-so7N8yAMoSPrhdwpBSA,2503
3
- crossplane/function/resource.py,sha256=DJhangADTadAcjemKFSirTZcmeCraCzp9XeD_fdyDKw,3251
4
- crossplane/function/response.py,sha256=fYJcPz5ZVN06hbNWXzy0tBTOMHNYQvj3m9JjWb2qRU8,2429
5
- crossplane/function/runtime.py,sha256=Nh-nn9bAkfOoXepTTzhNs5nMH8a7JaMfSE2dP5-0E7U,3430
6
- crossplane/function/proto/v1beta1/run_function.proto,sha256=yfw7XP13fOZt0fH2ttOd0hS0ULOV6ngn4KHJgKKnEKA,9301
7
- crossplane/function/proto/v1beta1/run_function_pb2.py,sha256=Br7NNcqwTLj3duAidqYF-AzVUGttBoIAT0gcZgH3fAQ,7730
8
- crossplane/function/proto/v1beta1/run_function_pb2.pyi,sha256=WAuOcfCE79aOZfD0H8I0ooGS2i7pHhj5MR-SHJv927s,7602
9
- crossplane/function/proto/v1beta1/run_function_pb2_grpc.py,sha256=iLQTF8CHQzjZlBGJUJTWPTfNSmm3ew02zGf6OPIsxVY,3026
10
- crossplane_function_sdk_python-0.2.0.dist-info/METADATA,sha256=DkXn9Tus_MVDO2AZTmGd37LOi_HJl-RfFmJkiViZRFc,3160
11
- crossplane_function_sdk_python-0.2.0.dist-info/WHEEL,sha256=TJPnKdtrSue7xZ_AVGkp9YXcvDrobsjBds1du3Nx6dc,87
12
- crossplane_function_sdk_python-0.2.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
13
- crossplane_function_sdk_python-0.2.0.dist-info/RECORD,,