Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

fix: make parent_id fields required compute move and insert methods (#686) #160

Merged
merged 4 commits into from Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 24 additions & 2 deletions google/cloud/compute_v1/services/firewall_policies/client.py
Expand Up @@ -981,6 +981,7 @@ def insert(
self,
request: Union[compute.InsertFirewallPolicyRequest, dict] = None,
*,
parent_id: str = None,
firewall_policy_resource: compute.FirewallPolicy = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
Expand All @@ -994,6 +995,15 @@ def insert(
The request object. A request message for
FirewallPolicies.Insert. See the method description for
details.
parent_id (str):
Parent ID for this request. The ID can be either be
"folders/[FOLDER_ID]" if the parent is a folder or
"organizations/[ORGANIZATION_ID]" if the parent is an
organization.

This corresponds to the ``parent_id`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
firewall_policy_resource (google.cloud.compute_v1.types.FirewallPolicy):
The body resource for this request
This corresponds to the ``firewall_policy_resource`` field
Expand Down Expand Up @@ -1027,7 +1037,7 @@ def insert(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([firewall_policy_resource])
has_flattened_params = any([parent_id, firewall_policy_resource])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
Expand All @@ -1042,6 +1052,8 @@ def insert(
request = compute.InsertFirewallPolicyRequest(request)
# If we have keyword arguments corresponding to fields on the
# request, apply these.
if parent_id is not None:
request.parent_id = parent_id
if firewall_policy_resource is not None:
request.firewall_policy_resource = firewall_policy_resource

Expand Down Expand Up @@ -1157,6 +1169,7 @@ def move(
request: Union[compute.MoveFirewallPolicyRequest, dict] = None,
*,
firewall_policy: str = None,
parent_id: str = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
Expand All @@ -1175,6 +1188,13 @@ def move(
This corresponds to the ``firewall_policy`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
parent_id (str):
The new parent of the firewall
policy.

This corresponds to the ``parent_id`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
retry (google.api_core.retry.Retry): Designation of what errors, if any,
should be retried.
timeout (float): The timeout for this request.
Expand Down Expand Up @@ -1203,7 +1223,7 @@ def move(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([firewall_policy])
has_flattened_params = any([firewall_policy, parent_id])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
Expand All @@ -1220,6 +1240,8 @@ def move(
# request, apply these.
if firewall_policy is not None:
request.firewall_policy = firewall_policy
if parent_id is not None:
request.parent_id = parent_id

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
Expand Down
Expand Up @@ -971,6 +971,7 @@ def _insert(

required_fields = [
# (snake_case_name, camel_case_name)
("parent_id", "parentId"),
]

request_kwargs = compute.InsertFirewallPolicyRequest.to_dict(request)
Expand Down Expand Up @@ -1214,6 +1215,7 @@ def _move(
required_fields = [
# (snake_case_name, camel_case_name)
("firewall_policy", "firewallPolicy"),
("parent_id", "parentId"),
]

request_kwargs = compute.MoveFirewallPolicyRequest.to_dict(request)
Expand Down
8 changes: 2 additions & 6 deletions google/cloud/compute_v1/types/compute.py
Expand Up @@ -20440,8 +20440,6 @@ class InsertFirewallPolicyRequest(proto.Message):
"folders/[FOLDER_ID]" if the parent is a folder or
"organizations/[ORGANIZATION_ID]" if the parent is an
organization.

This field is a member of `oneof`_ ``_parent_id``.
request_id (str):
An optional request ID to identify requests.
Specify a unique request ID so that if you must
Expand All @@ -20465,7 +20463,7 @@ class InsertFirewallPolicyRequest(proto.Message):
firewall_policy_resource = proto.Field(
proto.MESSAGE, number=495049532, message="FirewallPolicy",
)
parent_id = proto.Field(proto.STRING, number=459714768, optional=True,)
parent_id = proto.Field(proto.STRING, number=459714768,)
request_id = proto.Field(proto.STRING, number=37109963, optional=True,)


Expand Down Expand Up @@ -34937,8 +34935,6 @@ class MoveFirewallPolicyRequest(proto.Message):
Name of the firewall policy to update.
parent_id (str):
The new parent of the firewall policy.

This field is a member of `oneof`_ ``_parent_id``.
request_id (str):
An optional request ID to identify requests.
Specify a unique request ID so that if you must
Expand All @@ -34960,7 +34956,7 @@ class MoveFirewallPolicyRequest(proto.Message):
"""

firewall_policy = proto.Field(proto.STRING, number=498173265,)
parent_id = proto.Field(proto.STRING, number=459714768, optional=True,)
parent_id = proto.Field(proto.STRING, number=459714768,)
request_id = proto.Field(proto.STRING, number=37109963, optional=True,)


Expand Down
7 changes: 6 additions & 1 deletion tests/unit/gapic/compute_v1/test_firewall_policies.py
Expand Up @@ -1671,6 +1671,7 @@ def test_insert_rest_flattened(transport: str = "rest"):

# get truthy value for each flattened field
mock_args = dict(
parent_id="parent_id_value",
firewall_policy_resource=compute.FirewallPolicy(
associations=[
compute.FirewallPolicyAssociation(
Expand Down Expand Up @@ -1703,6 +1704,7 @@ def test_insert_rest_flattened_error(transport: str = "rest"):
with pytest.raises(ValueError):
client.insert(
compute.InsertFirewallPolicyRequest(),
parent_id="parent_id_value",
firewall_policy_resource=compute.FirewallPolicy(
associations=[
compute.FirewallPolicyAssociation(
Expand Down Expand Up @@ -2004,7 +2006,9 @@ def test_move_rest_flattened(transport: str = "rest"):
sample_request = {"firewall_policy": "sample1"}

# get truthy value for each flattened field
mock_args = dict(firewall_policy="firewall_policy_value",)
mock_args = dict(
firewall_policy="firewall_policy_value", parent_id="parent_id_value",
)
mock_args.update(sample_request)
client.move(**mock_args)

Expand All @@ -2030,6 +2034,7 @@ def test_move_rest_flattened_error(transport: str = "rest"):
client.move(
compute.MoveFirewallPolicyRequest(),
firewall_policy="firewall_policy_value",
parent_id="parent_id_value",
)


Expand Down