Compare commits

...

89 Commits
v0.5.0 ... main

Author SHA1 Message Date
Bob Haddleton 6e65599e58
Merge pull request #150 from crossplane/renovate/ruff-0.x
chore(deps): update dependency ruff to v0.11.9
2025-05-09 11:41:51 -05:00
Bob Haddleton a5cde9d9ee
Merge pull request #149 from crossplane/renovate/ipython-9.x
chore(deps): update dependency ipython to v9.2.0
2025-05-09 11:41:21 -05:00
renovate[bot] f99b12c0de
chore(deps): update dependency ruff to v0.11.9 2025-05-09 16:39:28 +00:00
Bob Haddleton 27e990f6aa
Merge pull request #146 from crossplane/renovate/protobuf-6.x
fix(deps): update dependency protobuf to v6
2025-05-09 11:39:03 -05:00
Nic Cope cf67e6d0fe
Merge pull request #147 from crossplane/renovate/ruff-0.x
chore(deps): update dependency ruff to v0.11.7
2025-04-28 15:11:45 -07:00
renovate[bot] 14b6502f33
chore(deps): update dependency ipython to v9.2.0 2025-04-25 19:49:36 +00:00
renovate[bot] 7a915c2df7
chore(deps): update dependency ruff to v0.11.7 2025-04-24 19:53:55 +00:00
Bob Haddleton 3931d503fc
Merge pull request #140 from negz/terminal
Shutdown gracefully on SIGTERM
2025-04-23 14:06:31 -05:00
renovate[bot] 82e60b0596
fix(deps): update dependency protobuf to v6 2025-04-23 19:05:17 +00:00
Bob Haddleton 57df02ae00
Merge pull request #144 from fernandezcuesta/fix/protobuf-gencode-misalignment
chore: update gRPC stubs
2025-04-23 14:04:50 -05:00
Bob Haddleton b1e9695250
Merge pull request #143 from crossplane/renovate/ipython-9.x
chore(deps): update dependency ipython to v9.1.0
2025-04-23 14:03:40 -05:00
Bob Haddleton 1f3d442276
Merge pull request #142 from crossplane/renovate/ruff-0.x
chore(deps): update dependency ruff to v0.11.6
2025-04-23 14:03:05 -05:00
renovate[bot] f0bb336ba5
chore(deps): update dependency ruff to v0.11.6 2025-04-17 16:36:17 +00:00
Jesús Fernández 47180d9798
**Summary:**
Functions depending on function-sdk-python 0.6.0 are giving a segmentation fault.
When (re)running the tests for this module, the following is shown:

```
runtime_version.py:98: UserWarning: Protobuf gencode version 5.29.0 is exactly one major version older than the runtime version 6.30.2 at crossplane/function/proto/v1beta1/run_function.proto. Please update the gencode to avoid compatibility violations in the next runtime release.
```

Apparently when renovatebot opened a PR with a bump up on `protobuf` version,
the major version change violated the constraint with `grpcio-tools`, which
has the following dependency:

```
Collecting protobuf<6.0dev,>=5.26.1 (from grpcio-tools==1.71.0)
```

This makes incompatible to have different versions of protobuf for the `build`
venv and the `generate` one.

Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
2025-04-10 12:11:43 +02:00
renovate[bot] 869fbfeb3d
chore(deps): update dependency ipython to v9.1.0 2025-04-07 10:26:46 +00:00
Bob Haddleton 9f55079121
Merge pull request #141 from crossplane/renovate/ruff-0.x
chore(deps): update dependency ruff to v0.11.3
2025-04-03 12:38:24 -05:00
renovate[bot] ed95373a01
chore(deps): update dependency ruff to v0.11.3 2025-04-03 14:31:41 +00:00
Nic Cope 0262a24330
Merge pull request #139 from negz/maintaining
Add OWNERS and CODEOWNERS
2025-04-02 14:29:53 +01:00
Nic Cope 8895e9d9af
Merge pull request #138 from negz/typical
Let tools know this library supports type hints
2025-04-02 14:29:30 +01:00
Nic Cope 1e0c20eb61
Merge pull request #135 from crossplane/renovate/grpcio-1.x
fix(deps): update dependency grpcio to v1.71.0
2025-04-01 07:05:09 -07:00
Nic Cope cdaf6697c5 Shutdown gracefully on SIGTERM
Signed-off-by: Nic Cope <nicc@rk0n.org>
2025-04-01 07:00:44 -07:00
Nic Cope fcec201f01 Run hatch fmt
This file wasn't formatted before making it into main. Not sure why the
linter didn't catch it...

Signed-off-by: Nic Cope <nicc@rk0n.org>
2025-04-01 06:59:38 -07:00
renovate[bot] 88d97d3cab
fix(deps): update dependency grpcio to v1.71.0 2025-04-01 13:43:23 +00:00
Nic Cope e2606cff9f Add OWNERS and CODEOWNERS
Signed-off-by: Nic Cope <nicc@rk0n.org>
2025-04-01 06:42:19 -07:00
Nic Cope f295c0144b Let tools know this library supports type hints
https://typing.python.org/en/latest/spec/distributing.html#packaging-type-information
https://typing.python.org/en/latest/guides/libraries.html#marking-a-package-as-providing-type-information

It turns out we need to add a py.typed file so that tools will know this
library has type hints. As far as I can tell we don't need to do
anything special to have our build tool (Hatch) include this file when
it builds and packages the library.

Signed-off-by: Nic Cope <nicc@rk0n.org>
2025-04-01 06:23:58 -07:00
Bob Haddleton 325c37d344
Merge pull request #133 from crossplane/renovate/protobuf-6.x
fix(deps): update dependency protobuf to v6
2025-03-31 14:21:07 -05:00
Bob Haddleton e6b771c3a6
Merge pull request #134 from crossplane/renovate/grpcio-tools-1.x
chore(deps): update dependency grpcio-tools to v1.71.0
2025-03-31 14:20:36 -05:00
Bob Haddleton 68cbf5f53e
Merge pull request #132 from crossplane/renovate/ipython-9.x
chore(deps): update dependency ipython to v9
2025-03-31 14:20:04 -05:00
renovate[bot] c8bcded971
chore(deps): update dependency ipython to v9 2025-03-31 19:17:37 +00:00
Bob Haddleton e0b964055b
Merge pull request #128 from crossplane/renovate/ruff-0.x
chore(deps): update dependency ruff to v0.11.2
2025-03-31 14:17:28 -05:00
Bob Haddleton 5c1e33baf4
Merge pull request #131 from crossplane/renovate/ipython-8.x
chore(deps): update dependency ipython to v8.34.0
2025-03-31 14:17:02 -05:00
renovate[bot] 466945254d
fix(deps): update dependency protobuf to v6 2025-03-26 19:58:40 +00:00
renovate[bot] 4fb63f221e
chore(deps): update dependency ruff to v0.11.2 2025-03-21 15:57:10 +00:00
renovate[bot] 26bdc926e8
chore(deps): update dependency grpcio-tools to v1.71.0 2025-03-10 22:00:28 +00:00
renovate[bot] 1e0f18263e
chore(deps): update dependency ipython to v8.34.0 2025-03-08 17:46:16 +00:00
Bob Haddleton 4ad65f2934
Merge pull request #127 from crossplane/renovate/ruff-0.x
chore(deps): update dependency ruff to v0.9.5
2025-02-06 16:33:38 -06:00
renovate[bot] aa09bd0632
chore(deps): update dependency ruff to v0.9.5 2025-02-06 21:13:29 +00:00
Bob Haddleton 0f188bcbde
Merge pull request #126 from crossplane/renovate/grpcio-1.x
fix(deps): update dependency grpcio to v1.70.0
2025-02-02 21:31:26 -06:00
renovate[bot] de5a11c59f
fix(deps): update dependency grpcio to v1.70.0 2025-02-01 21:16:32 +00:00
Bob Haddleton afa27a3121
Merge pull request #102 from fernandezcuesta/main
fix: convert listValues to lists in nested structs
2025-02-01 15:16:07 -06:00
Bob Haddleton aaf3d08879
Merge pull request #124 from crossplane/renovate/ruff-0.x
chore(deps): update dependency ruff to v0.9.4
2025-02-01 15:14:32 -06:00
Bob Haddleton aff844707c
Merge pull request #125 from crossplane/renovate/ipython-8.x
chore(deps): update dependency ipython to v8.32.0
2025-02-01 15:14:03 -06:00
renovate[bot] fb5d6fa5ab
chore(deps): update dependency ipython to v8.32.0 2025-02-01 21:11:14 +00:00
renovate[bot] 8525cebb57
chore(deps): update dependency ruff to v0.9.4 2025-01-30 19:15:14 +00:00
Bob Haddleton 597f5ee437
Merge pull request #119 from crossplane/renovate/ruff-0.x
chore(deps): update dependency ruff to v0.9.3
2025-01-27 12:05:54 -06:00
Bob Haddleton ce63739286
Merge pull request #120 from crossplane/renovate/structlog-25.x
fix(deps): update dependency structlog to v25
2025-01-27 12:05:25 -06:00
Bob Haddleton dbc0d0176b
Merge pull request #123 from crossplane/renovate/pypa-gh-action-pypi-publish-1.x
chore(deps): update pypa/gh-action-pypi-publish action to v1.12.4
2025-01-27 12:04:52 -06:00
Bob Haddleton d3bad9135d
Merge pull request #122 from crossplane/renovate/grpcio-tools-1.x
chore(deps): update dependency grpcio-tools to v1.70.0
2025-01-27 12:04:22 -06:00
renovate[bot] b6d553bdaf
chore(deps): update pypa/gh-action-pypi-publish action to v1.12.4 2025-01-24 05:16:53 +00:00
renovate[bot] cd38d99a5c
chore(deps): update dependency grpcio-tools to v1.70.0 2025-01-23 23:00:08 +00:00
renovate[bot] 0932de3e5d
chore(deps): update dependency ruff to v0.9.3 2025-01-23 23:00:05 +00:00
renovate[bot] 47d0d54b26
fix(deps): update dependency structlog to v25 2025-01-16 18:16:24 +00:00
J. Fernández 54d6e39371
Merge branch 'main' into main 2025-01-15 10:01:42 +01:00
Bob Haddleton 8551576b1f
Merge pull request #118 from crossplane/renovate/ruff-0.x
chore(deps): update dependency ruff to v0.9.1
2025-01-14 13:55:18 -06:00
renovate[bot] f1ae43e725
chore(deps): update dependency ruff to v0.9.1 2025-01-10 21:12:29 +00:00
Bob Haddleton 192b1d0b7a
Merge pull request #117 from crossplane/renovate/ruff-0.x
chore(deps): update dependency ruff to v0.9.0
2025-01-09 11:44:55 -06:00
renovate[bot] a82962a952
chore(deps): update dependency ruff to v0.9.0 2025-01-09 17:42:43 +00:00
Bob Haddleton 0651813b59
Merge pull request #116 from crossplane/renovate/protobuf-5.x
fix(deps): update dependency protobuf to v5.29.3
2025-01-09 11:42:20 -06:00
renovate[bot] 8f57f81ea1
fix(deps): update dependency protobuf to v5.29.3 2025-01-09 01:22:39 +00:00
Bob Haddleton 2c8b642afd
Merge pull request #110 from crossplane/renovate/ipython-8.x
chore(deps): update dependency ipython to v8.31.0
2025-01-08 14:30:31 -06:00
renovate[bot] 479335d1e3
chore(deps): update dependency ipython to v8.31.0 2025-01-08 20:16:39 +00:00
Bob Haddleton 84cf34e482
Merge pull request #107 from crossplane/renovate/ruff-0.x
chore(deps): update dependency ruff to v0.8.6
2025-01-08 13:56:36 -06:00
Bob Haddleton 81df679319
Merge pull request #111 from crossplane/renovate/pypa-gh-action-pypi-publish-1.x
chore(deps): update pypa/gh-action-pypi-publish action to v1.12.3
2025-01-08 13:53:15 -06:00
renovate[bot] 773346f3f8
chore(deps): update dependency ruff to v0.8.6 2025-01-08 19:52:55 +00:00
Bob Haddleton 77f1f6e8dd
Merge pull request #105 from crossplane/renovate/grpcio-tools-1.x
chore(deps): update dependency grpcio-tools to v1.69.0
2025-01-08 13:52:21 -06:00
renovate[bot] b8dd9ec256
chore(deps): update dependency grpcio-tools to v1.69.0 2025-01-08 19:50:52 +00:00
renovate[bot] 6b3e0cbcc4
chore(deps): update pypa/gh-action-pypi-publish action to v1.12.3 2025-01-08 19:50:30 +00:00
Bob Haddleton d9e26f5b03
Merge pull request #89 from crossplane/renovate/protobuf-5.x
fix(deps): update dependency protobuf to v5.29.2
2025-01-08 13:49:57 -06:00
renovate[bot] 5139481ee5
fix(deps): update dependency protobuf to v5.29.2 2025-01-08 19:48:30 +00:00
Nic Cope a8999723f4
Merge pull request #115 from bobh66/fix_bucket_version
fix(unittests): fix bucket api version
2025-01-08 11:47:05 -08:00
Bob Haddleton 9ef55d251c fix(unittests): fix bucket api version 2025-01-08 13:33:33 -06:00
Nic Cope 064ffe7458
Merge pull request #112 from crossplane/fix_unit_tests
Bump protobuf and add defensive checks to get_* helpers
2025-01-08 11:19:46 -08:00
Nic Cope d4b3506ec7
Merge pull request #114 from haarchri/test
Pydantic, exclude_defaults=True re-add `apiVersion` and `kind`
2025-01-08 11:18:57 -08:00
Christopher Haar 70e86c0d30 fix(defaults): add apiVersion and kind
Signed-off-by: Christopher Haar <christopher.haar@upbound.io>
2025-01-06 17:10:32 +01:00
Bob Haddleton 685918f02d Bump protobuf and add defensive checks to get_* helpers
Signed-off-by: Bob Haddleton <bob.haddleton@nokia.com>
2024-12-18 14:27:11 -06:00
Bob Haddleton 9c44291da2
Merge pull request #106 from crossplane/renovate/pypa-gh-action-pypi-publish-1.x
chore(deps): update pypa/gh-action-pypi-publish action to v1.12.2
2024-11-30 14:54:48 -06:00
Jesús Fernández 36e5600356
chore: stick to grpcio 1.67.0
Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
2024-11-26 20:04:55 +01:00
J. Fernández 5cf7fffbf1
bump protobuf
Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
2024-11-26 19:55:16 +01:00
Jesús Fernández c632b0c1ad
feat: use json_format.ParseDict to convert dicts to structs
Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
2024-11-25 12:08:06 +01:00
Jesús Fernández 25e49cf3bd
fix: structs containing listvalues are properly converted
Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
2024-11-13 22:23:14 +01:00
renovate[bot] 7452119ba8
chore(deps): update pypa/gh-action-pypi-publish action to v1.12.2 2024-11-07 01:51:37 +00:00
Bob Haddleton 870edfcd76
Merge pull request #104 from crossplane/renovate/ipython-8.x
chore(deps): update dependency ipython to v8.29.0
2024-10-25 07:52:00 -05:00
Bob Haddleton fc8796d42b
Merge pull request #103 from crossplane/renovate/ruff-0.x
chore(deps): update dependency ruff to v0.7.1
2024-10-25 07:51:07 -05:00
renovate[bot] 569af1d6d3
chore(deps): update dependency ipython to v8.29.0 2024-10-25 10:48:41 +00:00
renovate[bot] 41eca588a1
chore(deps): update dependency ruff to v0.7.1 2024-10-24 16:33:59 +00:00
Bob Haddleton 50086a69b2
Merge pull request #101 from crossplane/renovate/ruff-0.x
chore(deps): update dependency ruff to v0.7.0
2024-10-17 22:40:11 -05:00
Bob Haddleton 1bf5f444e4
Merge pull request #100 from crossplane/renovate/grpcio-tools-1.x
chore(deps): update dependency grpcio-tools to v1.67.0
2024-10-17 22:39:31 -05:00
renovate[bot] 5a3e1536ee
chore(deps): update dependency ruff to v0.7.0 2024-10-17 17:25:30 +00:00
renovate[bot] 6a256486e2
chore(deps): update dependency grpcio-tools to v1.67.0 2024-10-16 08:53:28 +00:00
13 changed files with 174 additions and 32 deletions

View File

@ -120,7 +120,7 @@ jobs:
path: "dist"
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@v1.10.3
uses: pypa/gh-action-pypi-publish@v1.12.4
with:
# Note that this is currently being pushed to the 'crossplane' PyPI
# user (not org). See @negz if you need access - PyPI requires 2FA to

22
CODEOWNERS Normal file
View File

@ -0,0 +1,22 @@
# SPDX-FileCopyrightText: 2025 The Crossplane Authors <https://crossplane.io>
#
# SPDX-License-Identifier: CC0-1.0
# This file controls automatic PR reviewer assignment. See the following docs:
#
# * https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners
# * https://docs.github.com/en/organizations/organizing-members-into-teams/managing-code-review-settings-for-your-team
#
# The goal of this file is for most PRs to automatically and fairly have one
# maintainer set as PR reviewers. All maintainers have permission to approve
# and merge PRs. All PRs must be approved by at least one maintainer before being merged.
#
# Where possible, prefer explicitly specifying a maintainer who is a subject
# matter expert for a particular part of the codebase rather than using fallback
# owners. Fallback owners are listed at the bottom of this file.
#
# See also OWNERS.md for governance details
# Fallback owners
* @negz @bobh66

18
OWNERS.md Normal file
View File

@ -0,0 +1,18 @@
<!--
SPDX-FileCopyrightText: 2025 The Crossplane Authors <https://crossplane.io>
SPDX-License-Identifier: CC-BY-4.0
-->
# OWNERS
This page lists all maintainers for **this** repository. Each repository in the
[Crossplane Contrib organization](https://github.com/crossplane-contrib/) will list their
repository maintainers in their own `OWNERS.md` file.
## Maintainers
* Nic Cope <negz@upbound.com> ([negz](https://github.com/negz))
* Bob Haddleton <bob.haddleton@nokia.com> ([bobh66](https://github.com/bobh66))
See [CODEOWNERS](./CODEOWNERS) for automatic PR assignment.

View File

@ -2,7 +2,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# NO CHECKED-IN PROTOBUF GENCODE
# source: crossplane/function/proto/v1/run_function.proto
# Protobuf Python Version: 5.27.2
# Protobuf Python Version: 5.29.0
"""Generated protocol buffer code."""
from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pool as _descriptor_pool
@ -12,8 +12,8 @@ from google.protobuf.internal import builder as _builder
_runtime_version.ValidateProtobufRuntimeVersion(
_runtime_version.Domain.PUBLIC,
5,
27,
2,
29,
0,
'',
'crossplane/function/proto/v1/run_function.proto'
)

View File

@ -5,7 +5,7 @@ import warnings
from crossplane.function.proto.v1 import run_function_pb2 as crossplane_dot_function_dot_proto_dot_v1_dot_run__function__pb2
GRPC_GENERATED_VERSION = '1.66.0'
GRPC_GENERATED_VERSION = '1.71.0'
GRPC_VERSION = grpc.__version__
_version_not_supported = False

View File

@ -2,7 +2,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# NO CHECKED-IN PROTOBUF GENCODE
# source: crossplane/function/proto/v1beta1/run_function.proto
# Protobuf Python Version: 5.27.2
# Protobuf Python Version: 5.29.0
"""Generated protocol buffer code."""
from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pool as _descriptor_pool
@ -12,8 +12,8 @@ from google.protobuf.internal import builder as _builder
_runtime_version.ValidateProtobufRuntimeVersion(
_runtime_version.Domain.PUBLIC,
5,
27,
2,
29,
0,
'',
'crossplane/function/proto/v1beta1/run_function.proto'
)

View File

@ -5,7 +5,7 @@ import warnings
from crossplane.function.proto.v1beta1 import run_function_pb2 as crossplane_dot_function_dot_proto_dot_v1beta1_dot_run__function__pb2
GRPC_GENERATED_VERSION = '1.66.0'
GRPC_GENERATED_VERSION = '1.71.0'
GRPC_VERSION = grpc.__version__
_version_not_supported = False

View File

View File

@ -18,6 +18,7 @@ import dataclasses
import datetime
import pydantic
from google.protobuf import json_format
from google.protobuf import struct_pb2 as structpb
import crossplane.function.proto.v1.run_function_pb2 as fnv1
@ -38,7 +39,15 @@ def update(r: fnv1.Resource, source: dict | structpb.Struct | pydantic.BaseModel
"""
match source:
case pydantic.BaseModel():
r.resource.update(source.model_dump(exclude_defaults=True, warnings=False))
data = source.model_dump(exclude_defaults=True, warnings=False)
# In Pydantic, exclude_defaults=True in model_dump excludes fields
# that have their value equal to the default. If a field like
# apiVersion is set to its default value 's3.aws.upbound.io/v1beta2'
# (and not explicitly provided during initialization), it will be
# excluded from the serialized output.
data["apiVersion"] = source.apiVersion
data["kind"] = source.kind
r.resource.update(data)
case structpb.Struct():
# TODO(negz): Use struct_to_dict and update to match other semantics?
r.resource.MergeFrom(source)
@ -57,9 +66,7 @@ def dict_to_struct(d: dict) -> structpb.Struct:
function makes it possible to work with a Python dict, then convert it to a
struct in a RunFunctionResponse.
"""
s = structpb.Struct()
s.update(d)
return s
return json_format.ParseDict(d, structpb.Struct())
def struct_to_dict(s: structpb.Struct) -> dict:
@ -69,10 +76,7 @@ def struct_to_dict(s: structpb.Struct) -> dict:
protobuf struct. This function makes it possible to convert resources to a
dictionary.
"""
return {
k: (struct_to_dict(v) if isinstance(v, structpb.Struct) else v)
for k, v in s.items()
}
return json_format.MessageToDict(s, preserving_proto_field_name=True)
@dataclasses.dataclass
@ -110,10 +114,10 @@ def get_condition(resource: structpb.Struct, typ: str) -> Condition:
"""
unknown = Condition(typ=typ, status="Unknown")
if "status" not in resource:
if not resource or "status" not in resource:
return unknown
if "conditions" not in resource["status"]:
if not resource["status"] or "conditions" not in resource["status"]:
return unknown
for c in resource["status"]["conditions"]:
@ -149,9 +153,9 @@ class Credentials:
def get_credentials(req: structpb.Struct, name: str) -> Credentials:
"""Get the supplied credentials."""
empty = Credentials(type="data", data={})
if "credentials" not in req:
if not req or "credentials" not in req:
return empty
if name not in req["credentials"]:
if not req["credentials"] or name not in req["credentials"]:
return empty
return Credentials(
type=req["credentials"][name]["type"],

View File

@ -16,6 +16,7 @@
import asyncio
import os
import signal
import grpc
from grpc_reflection.v1alpha import reflection
@ -31,6 +32,8 @@ SERVICE_NAMES = (
fnv1beta1.DESCRIPTOR.services_by_name["FunctionRunnerService"].full_name,
)
SHUTDOWN_GRACE_PERIOD_SECONDS = 5
def load_credentials(tls_certs_dir: str) -> grpc.ServerCredentials:
"""Load TLS credentials for a composition function gRPC server.
@ -90,6 +93,11 @@ def serve(
server = grpc.aio.server()
loop.add_signal_handler(
signal.SIGTERM,
lambda: asyncio.ensure_future(server.stop(grace=SHUTDOWN_GRACE_PERIOD_SECONDS)),
)
grpcv1.add_FunctionRunnerServiceServicer_to_server(function, server)
grpcv1beta1.add_FunctionRunnerServiceServicer_to_server(
BetaFunctionRunner(wrapped=function), server
@ -116,7 +124,7 @@ def serve(
try:
loop.run_until_complete(start())
finally:
loop.run_until_complete(server.stop(grace=5))
loop.run_until_complete(server.stop(grace=SHUTDOWN_GRACE_PERIOD_SECONDS))
loop.close()

View File

@ -14,14 +14,15 @@ classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python",
"Programming Language :: Python :: 3.11",
"Typing :: Typed",
]
dependencies = [
"grpcio==1.*",
"grpcio==1.71.0",
"grpcio-reflection==1.*",
"protobuf==5.27.2",
"protobuf==6.30.2", # Must be compatible with grpcio-tools.
"pydantic==2.*",
"structlog==24.*",
"structlog==25.*",
]
dynamic = ["version"]
@ -38,13 +39,16 @@ validate-bump = false # Allow going from 0.0.0.dev0+x to 0
[tool.hatch.envs.default]
type = "virtual"
path = ".venv-default"
dependencies = ["ipython==8.28.0"]
dependencies = ["ipython==9.2.0"]
[tool.hatch.envs.generate]
type = "virtual"
detached = true
path = ".venv-generate"
dependencies = ["grpcio-tools==1.66.2"]
dependencies = [
"grpcio-tools==1.71.0",
"protobuf==6.30.2",
]
[tool.hatch.envs.generate.scripts]
protoc = "python -m grpc_tools.protoc --proto_path=. --python_out=. --pyi_out=. --grpc_python_out=. crossplane/function/proto/v1beta1/run_function.proto crossplane/function/proto/v1/run_function.proto"
@ -62,8 +66,8 @@ packages = ["crossplane"]
# This special environment is used by hatch fmt.
[tool.hatch.envs.hatch-static-analysis]
dependencies = ["ruff==0.6.9"]
config-path = "none" # Disable Hatch's default Ruff config.
dependencies = ["ruff==0.11.9"]
config-path = "none" # Disable Hatch's default Ruff config.
[tool.ruff]
target-version = "py311"

View File

@ -90,7 +90,11 @@ class TestResource(unittest.TestCase):
),
want=fnv1.Resource(
resource=resource.dict_to_struct(
{"spec": {"forProvider": {"region": "us-west-2"}}}
{
"apiVersion": "s3.aws.upbound.io/v1beta2",
"kind": "Bucket",
"spec": {"forProvider": {"region": "us-west-2"}},
}
),
),
),
@ -244,6 +248,66 @@ class TestResource(unittest.TestCase):
dataclasses.asdict(case.want), dataclasses.asdict(got), "-want, +got"
)
def test_dict_to_struct(self) -> None:
@dataclasses.dataclass
class TestCase:
reason: str
d: dict
want: structpb.Struct
cases = [
TestCase(
reason="Convert an empty dictionary to a struct.",
d={},
want=structpb.Struct(),
),
TestCase(
reason="Convert a dictionary with a single field to a struct.",
d={"foo": "bar"},
want=structpb.Struct(
fields={"foo": structpb.Value(string_value="bar")}
),
),
TestCase(
reason="Convert a nested dictionary to a struct.",
d={"foo": {"bar": "baz"}},
want=structpb.Struct(
fields={
"foo": structpb.Value(
struct_value=structpb.Struct(
fields={"bar": structpb.Value(string_value="baz")}
)
)
}
),
),
TestCase(
reason="Convert a nested dictionary containing lists to a struct.",
d={"foo": {"bar": ["baz", "qux"]}},
want=structpb.Struct(
fields={
"foo": structpb.Value(
struct_value=structpb.Struct(
fields={
"bar": structpb.Value(
list_value=structpb.ListValue(
values=[
structpb.Value(string_value="baz"),
structpb.Value(string_value="qux"),
]
)
)
}
)
)
}
),
),
]
for case in cases:
got = resource.dict_to_struct(case.d)
self.assertEqual(case.want, got, "-want, +got")
def test_struct_to_dict(self) -> None:
@dataclasses.dataclass
class TestCase:
@ -275,6 +339,28 @@ class TestResource(unittest.TestCase):
),
want={"foo": {"bar": "baz"}},
),
TestCase(
reason="Convert a nested struct containing ListValues to a dictionary.",
s=structpb.Struct(
fields={
"foo": structpb.Value(
struct_value=structpb.Struct(
fields={
"bar": structpb.Value(
list_value=structpb.ListValue(
values=[
structpb.Value(string_value="baz"),
structpb.Value(string_value="qux"),
]
)
)
}
)
)
}
),
want={"foo": {"bar": ["baz", "qux"]}},
),
]
for case in cases:

View File

@ -759,11 +759,11 @@ class Status(BaseModel):
class Bucket(BaseModel):
apiVersion: Optional[str] = None
apiVersion: Optional[str] = 's3.aws.upbound.io/v1beta2'
"""
APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
"""
kind: Optional[str] = None
kind: Optional[str] = 'Bucket'
"""
Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
"""