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