diff --git a/README.md b/README.md index 14bc03f..6516e1b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # function-template-python + [![CI](https://github.com/crossplane/function-template-python/actions/workflows/ci.yml/badge.svg)](https://github.com/crossplane/function-template-go/actions/workflows/ci.yml) A template for writing a [composition function][functions] in [Python][python]. diff --git a/function/fn.py b/function/fn.py index ca734d6..705121b 100644 --- a/function/fn.py +++ b/function/fn.py @@ -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") diff --git a/pyproject.toml b/pyproject.toml index 3b006ec..a2141ec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", ] diff --git a/tests/test_fn.py b/tests/test_fn.py index b98aa5b..0c111ee 100644 --- a/tests/test_fn.py +++ b/tests/test_fn.py @@ -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!", ) ],