From 8b373af2458ad18c29fdf112daf512a7120ce528 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Wed, 1 Dec 2021 05:54:25 -0500 Subject: [PATCH] fix: make parent_id fields required compute move and insert methods (#686) (#160) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: make parent_id fields required compute move and insert methods (#686) Source-Link: https://github.com/googleapis/googleapis/commit/02df998e40733c077aa0fc3f35a6b2d48aa8bf84 Source-Link: https://github.com/googleapis/googleapis-gen/commit/a3638a868dc34a573cc99a8cd0ac74b82ebdabc6 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYTM2MzhhODY4ZGMzNGE1NzNjYzk5YThjZDBhYzc0YjgyZWJkYWJjNiJ9 * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot --- .../services/firewall_policies/client.py | 26 +++++++++++++++++-- .../firewall_policies/transports/rest.py | 2 ++ google/cloud/compute_v1/types/compute.py | 8 ++---- .../compute_v1/test_firewall_policies.py | 7 ++++- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/google/cloud/compute_v1/services/firewall_policies/client.py b/google/cloud/compute_v1/services/firewall_policies/client.py index 9de6ec5f7..c49d83298 100644 --- a/google/cloud/compute_v1/services/firewall_policies/client.py +++ b/google/cloud/compute_v1/services/firewall_policies/client.py @@ -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, @@ -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 @@ -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 " @@ -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 @@ -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]] = (), @@ -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. @@ -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 " @@ -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. diff --git a/google/cloud/compute_v1/services/firewall_policies/transports/rest.py b/google/cloud/compute_v1/services/firewall_policies/transports/rest.py index d74033c18..2a4aa3df6 100644 --- a/google/cloud/compute_v1/services/firewall_policies/transports/rest.py +++ b/google/cloud/compute_v1/services/firewall_policies/transports/rest.py @@ -971,6 +971,7 @@ def _insert( required_fields = [ # (snake_case_name, camel_case_name) + ("parent_id", "parentId"), ] request_kwargs = compute.InsertFirewallPolicyRequest.to_dict(request) @@ -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) diff --git a/google/cloud/compute_v1/types/compute.py b/google/cloud/compute_v1/types/compute.py index 0d9dca3df..2d156771c 100644 --- a/google/cloud/compute_v1/types/compute.py +++ b/google/cloud/compute_v1/types/compute.py @@ -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 @@ -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,) @@ -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 @@ -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,) diff --git a/tests/unit/gapic/compute_v1/test_firewall_policies.py b/tests/unit/gapic/compute_v1/test_firewall_policies.py index 8d86d8369..ddcf90bc0 100644 --- a/tests/unit/gapic/compute_v1/test_firewall_policies.py +++ b/tests/unit/gapic/compute_v1/test_firewall_policies.py @@ -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( @@ -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( @@ -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) @@ -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", )