Merge pull request #83 from stevendborrelli/v0.4.0-sdk
update to v1 types
This commit is contained in:
commit
bedea346f7
|
@ -1,4 +1,5 @@
|
|||
# function-template-python
|
||||
|
||||
[](https://github.com/crossplane/function-template-go/actions/workflows/ci.yml)
|
||||
|
||||
A template for writing a [composition function][functions] in [Python][python].
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
import grpc
|
||||
from crossplane.function import logging, response
|
||||
from crossplane.function.proto.v1beta1 import run_function_pb2 as fnv1beta1
|
||||
from crossplane.function.proto.v1beta1 import run_function_pb2_grpc as grpcv1beta1
|
||||
from crossplane.function.proto.v1 import run_function_pb2 as fnv1
|
||||
from crossplane.function.proto.v1 import run_function_pb2_grpc as grpcv1
|
||||
|
||||
|
||||
class FunctionRunner(grpcv1beta1.FunctionRunnerService):
|
||||
class FunctionRunner(grpcv1.FunctionRunnerService):
|
||||
"""A FunctionRunner handles gRPC RunFunctionRequests."""
|
||||
|
||||
def __init__(self):
|
||||
|
@ -14,8 +14,8 @@ class FunctionRunner(grpcv1beta1.FunctionRunnerService):
|
|||
self.log = logging.get_logger()
|
||||
|
||||
async def RunFunction(
|
||||
self, req: fnv1beta1.RunFunctionRequest, _: grpc.aio.ServicerContext
|
||||
) -> fnv1beta1.RunFunctionResponse:
|
||||
self, req: fnv1.RunFunctionRequest, _: grpc.aio.ServicerContext
|
||||
) -> fnv1.RunFunctionResponse:
|
||||
"""Run the function."""
|
||||
log = self.log.bind(tag=req.meta.tag)
|
||||
log.info("Running function")
|
||||
|
|
|
@ -18,7 +18,7 @@ classifiers = [
|
|||
]
|
||||
|
||||
dependencies = [
|
||||
"crossplane-function-sdk-python==0.3.0",
|
||||
"crossplane-function-sdk-python==0.4.0",
|
||||
"click==8.1.7",
|
||||
"grpcio==1.66.1",
|
||||
]
|
||||
|
|
|
@ -2,7 +2,7 @@ import dataclasses
|
|||
import unittest
|
||||
|
||||
from crossplane.function import logging, resource
|
||||
from crossplane.function.proto.v1beta1 import run_function_pb2 as fnv1beta1
|
||||
from crossplane.function.proto.v1 import run_function_pb2 as fnv1
|
||||
from google.protobuf import duration_pb2 as durationpb
|
||||
from google.protobuf import json_format
|
||||
from google.protobuf import struct_pb2 as structpb
|
||||
|
@ -21,21 +21,21 @@ class TestFunctionRunner(unittest.IsolatedAsyncioTestCase):
|
|||
@dataclasses.dataclass
|
||||
class TestCase:
|
||||
reason: str
|
||||
req: fnv1beta1.RunFunctionRequest
|
||||
want: fnv1beta1.RunFunctionResponse
|
||||
req: fnv1.RunFunctionRequest
|
||||
want: fnv1.RunFunctionResponse
|
||||
|
||||
cases = [
|
||||
TestCase(
|
||||
reason="The function should return the input as a result.",
|
||||
req=fnv1beta1.RunFunctionRequest(
|
||||
req=fnv1.RunFunctionRequest(
|
||||
input=resource.dict_to_struct({"example": "Hello, world"})
|
||||
),
|
||||
want=fnv1beta1.RunFunctionResponse(
|
||||
meta=fnv1beta1.ResponseMeta(ttl=durationpb.Duration(seconds=60)),
|
||||
desired=fnv1beta1.State(),
|
||||
want=fnv1.RunFunctionResponse(
|
||||
meta=fnv1.ResponseMeta(ttl=durationpb.Duration(seconds=60)),
|
||||
desired=fnv1.State(),
|
||||
results=[
|
||||
fnv1beta1.Result(
|
||||
severity=fnv1beta1.SEVERITY_NORMAL,
|
||||
fnv1.Result(
|
||||
severity=fnv1.SEVERITY_NORMAL,
|
||||
message="I was run with input Hello, world!",
|
||||
)
|
||||
],
|
||||
|
|
Loading…
Reference in New Issue