Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandezcuesta authored Jan 15, 2025
2 parents 36e5600 + 8551576 commit 54d6e39
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.3
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
Expand Down
18 changes: 13 additions & 5 deletions crossplane/function/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,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)
Expand Down Expand Up @@ -106,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"]:
Expand Down Expand Up @@ -145,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"],
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ classifiers = [
dependencies = [
"grpcio==1.67.0",
"grpcio-reflection==1.*",
"protobuf==5.27.2",
"protobuf==5.29.3",
"pydantic==2.*",
"structlog==24.*",
]
Expand All @@ -38,13 +38,13 @@ 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==8.31.0"]

[tool.hatch.envs.generate]
type = "virtual"
detached = true
path = ".venv-generate"
dependencies = ["grpcio-tools==1.67.0"]
dependencies = ["grpcio-tools==1.69.0"]

[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"
Expand All @@ -62,7 +62,7 @@ packages = ["crossplane"]

# This special environment is used by hatch fmt.
[tool.hatch.envs.hatch-static-analysis]
dependencies = ["ruff==0.6.9"]
dependencies = ["ruff==0.9.1"]
config-path = "none" # Disable Hatch's default Ruff config.

[tool.ruff]
Expand Down
6 changes: 5 additions & 1 deletion tests/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ class 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"}},
}
),
),
),
Expand Down
4 changes: 2 additions & 2 deletions tests/testdata/models/io/upbound/aws/s3/v1beta2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down

0 comments on commit 54d6e39

Please sign in to comment.