From 1f99b73f5ae4be127037e9b84d5bdce57b1f46dc Mon Sep 17 00:00:00 2001 From: yoshi-automation Date: Sat, 15 May 2021 04:34:07 +0000 Subject: [PATCH 01/12] changes without context autosynth cannot find the source of changes triggered by earlier changes in this repository, or by version upgrades to tools such as linters. --- .pre-commit-config.yaml | 2 +- synth.metadata | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1bbd787..4f00c7c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -26,6 +26,6 @@ repos: hooks: - id: black - repo: https://gitlab.com/pycqa/flake8 - rev: 3.9.1 + rev: 3.9.2 hooks: - id: flake8 diff --git a/synth.metadata b/synth.metadata index 050d164..7109cf9 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,7 +4,7 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/python-binary-authorization.git", - "sha": "82b3583c8dbc897dbb192ffc2051de5169d934c2" + "sha": "996f5010afd4372d625a9accc57647bac46770a8" } }, { From 0dc581b373c468df7dd5d50cd15a73cfb46dab08 Mon Sep 17 00:00:00 2001 From: yoshi-automation Date: Sat, 15 May 2021 04:39:50 +0000 Subject: [PATCH 02/12] chore: upgrade gapic-generator-python to 0.43.2 PiperOrigin-RevId: 366826395 Source-Author: Google APIs Source-Date: Mon Apr 5 10:39:44 2021 -0700 Source-Repo: googleapis/googleapis Source-Sha: 2490be32f08cccc870862ea86920f58325795c89 Source-Link: https://github.com/googleapis/googleapis/commit/2490be32f08cccc870862ea86920f58325795c89 --- .../async_client.py | 12 ++++++------ .../binauthz_management_service_v1_beta1/client.py | 12 ++++++------ .../binaryauthorization_v1beta1/types/service.py | 4 ++-- .../fixup_binaryauthorization_v1beta1_keywords.py | 2 +- synth.metadata | 4 ++-- .../test_binauthz_management_service_v1_beta1.py | 12 ++++++------ 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py index 8876be6..c8c2474 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py @@ -299,7 +299,7 @@ async def update_policy( self, request: service.UpdatePolicyRequest = None, *, - policy: resources.Policy = None, + policy_: resources.Policy = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -317,7 +317,7 @@ async def update_policy( request (:class:`google.cloud.binaryauthorization_v1beta1.types.UpdatePolicyRequest`): The request object. Request message for [BinauthzManagementService.UpdatePolicy][]. - policy (:class:`google.cloud.binaryauthorization_v1beta1.types.Policy`): + policy_ (:class:`google.cloud.binaryauthorization_v1beta1.types.Policy`): Required. A new or updated [policy][google.cloud.binaryauthorization.v1beta1.Policy] value. The service will overwrite the [policy @@ -325,7 +325,7 @@ async def update_policy( field with the resource name in the request URL, in the format ``projects/*/policy``. - This corresponds to the ``policy`` field + This corresponds to the ``policy_`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -344,7 +344,7 @@ async def update_policy( # 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([policy]) + has_flattened_params = any([policy_]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -356,8 +356,8 @@ async def update_policy( # If we have keyword arguments corresponding to fields on the # request, apply these. - if policy is not None: - request.policy = policy + if policy_ is not None: + request.policy_ = policy_ # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py index aac65a5..4dbbd25 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py @@ -464,7 +464,7 @@ def update_policy( self, request: service.UpdatePolicyRequest = None, *, - policy: resources.Policy = None, + policy_: resources.Policy = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -482,7 +482,7 @@ def update_policy( request (google.cloud.binaryauthorization_v1beta1.types.UpdatePolicyRequest): The request object. Request message for [BinauthzManagementService.UpdatePolicy][]. - policy (google.cloud.binaryauthorization_v1beta1.types.Policy): + policy_ (google.cloud.binaryauthorization_v1beta1.types.Policy): Required. A new or updated [policy][google.cloud.binaryauthorization.v1beta1.Policy] value. The service will overwrite the [policy @@ -490,7 +490,7 @@ def update_policy( field with the resource name in the request URL, in the format ``projects/*/policy``. - This corresponds to the ``policy`` field + This corresponds to the ``policy_`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -509,7 +509,7 @@ def update_policy( # 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([policy]) + has_flattened_params = any([policy_]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -526,8 +526,8 @@ def update_policy( # If we have keyword arguments corresponding to fields on the # request, apply these. - if policy is not None: - request.policy = policy + if policy_ is not None: + request.policy_ = policy_ # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. diff --git a/google/cloud/binaryauthorization_v1beta1/types/service.py b/google/cloud/binaryauthorization_v1beta1/types/service.py index d219341..c77d251 100644 --- a/google/cloud/binaryauthorization_v1beta1/types/service.py +++ b/google/cloud/binaryauthorization_v1beta1/types/service.py @@ -53,7 +53,7 @@ class UpdatePolicyRequest(proto.Message): r"""Request message for [BinauthzManagementService.UpdatePolicy][]. Attributes: - policy (google.cloud.binaryauthorization_v1beta1.types.Policy): + policy_ (google.cloud.binaryauthorization_v1beta1.types.Policy): Required. A new or updated [policy][google.cloud.binaryauthorization.v1beta1.Policy] value. The service will overwrite the [policy @@ -62,7 +62,7 @@ class UpdatePolicyRequest(proto.Message): format ``projects/*/policy``. """ - policy = proto.Field(proto.MESSAGE, number=1, message=resources.Policy,) + policy_ = proto.Field(proto.MESSAGE, number=1, message=resources.Policy,) class CreateAttestorRequest(proto.Message): diff --git a/scripts/fixup_binaryauthorization_v1beta1_keywords.py b/scripts/fixup_binaryauthorization_v1beta1_keywords.py index 6d42b25..56d9bd4 100644 --- a/scripts/fixup_binaryauthorization_v1beta1_keywords.py +++ b/scripts/fixup_binaryauthorization_v1beta1_keywords.py @@ -47,7 +47,7 @@ class binaryauthorizationCallTransformer(cst.CSTTransformer): 'get_policy': ('name', ), 'list_attestors': ('parent', 'page_size', 'page_token', ), 'update_attestor': ('attestor', ), - 'update_policy': ('policy', ), + 'update_policy': ('policy_', ), } diff --git a/synth.metadata b/synth.metadata index 7109cf9..f9cf74d 100644 --- a/synth.metadata +++ b/synth.metadata @@ -11,8 +11,8 @@ "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "56fc6d43fed71188d7e18f3ca003544646c4ab35", - "internalRef": "366346972" + "sha": "2490be32f08cccc870862ea86920f58325795c89", + "internalRef": "366826395" } } ], diff --git a/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py b/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py index 0c18968..cb13870 100644 --- a/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py +++ b/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py @@ -910,14 +910,14 @@ def test_update_policy_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.update_policy(policy=resources.Policy(name="name_value"),) + client.update_policy(policy_=resources.Policy(name="name_value"),) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].policy == resources.Policy(name="name_value") + assert args[0].policy_ == resources.Policy(name="name_value") def test_update_policy_flattened_error(): @@ -929,7 +929,7 @@ def test_update_policy_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.update_policy( - service.UpdatePolicyRequest(), policy=resources.Policy(name="name_value"), + service.UpdatePolicyRequest(), policy_=resources.Policy(name="name_value"), ) @@ -948,7 +948,7 @@ async def test_update_policy_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.update_policy( - policy=resources.Policy(name="name_value"), + policy_=resources.Policy(name="name_value"), ) # Establish that the underlying call was made with the expected @@ -956,7 +956,7 @@ async def test_update_policy_flattened_async(): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].policy == resources.Policy(name="name_value") + assert args[0].policy_ == resources.Policy(name="name_value") @pytest.mark.asyncio @@ -969,7 +969,7 @@ async def test_update_policy_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.update_policy( - service.UpdatePolicyRequest(), policy=resources.Policy(name="name_value"), + service.UpdatePolicyRequest(), policy_=resources.Policy(name="name_value"), ) From e063206685e49ba6b07dea8a70f00f852af5a06f Mon Sep 17 00:00:00 2001 From: yoshi-automation Date: Sat, 15 May 2021 04:41:33 +0000 Subject: [PATCH 03/12] chore: upgrade to gapic-generator-python 0.44.0 chore: add GAPIC metadata feat: add support for self-signed JWT PiperOrigin-RevId: 370525906 Source-Author: Google APIs Source-Date: Mon Apr 26 13:12:26 2021 -0700 Source-Repo: googleapis/googleapis Source-Sha: 60e129d0672a1be2c70b41bf76aadc7ad1b1ca0f Source-Link: https://github.com/googleapis/googleapis/commit/60e129d0672a1be2c70b41bf76aadc7ad1b1ca0f --- .coveragerc | 1 - .../binauthz_management_service_v1_beta1.rst | 1 - docs/binaryauthorization_v1beta1/services.rst | 2 +- google/cloud/binaryauthorization/__init__.py | 1 - .../binaryauthorization_v1beta1/__init__.py | 3 +- .../gapic_metadata.json | 93 +++++ .../services/__init__.py | 1 - .../__init__.py | 2 - .../async_client.py | 44 +-- .../client.py | 45 +-- .../pagers.py | 2 - .../transports/__init__.py | 2 - .../transports/base.py | 117 ++++-- .../transports/grpc.py | 42 ++- .../transports/grpc_asyncio.py | 44 ++- .../types/__init__.py | 2 - .../types/resources.py | 159 +++++--- .../types/service.py | 34 +- ...up_binaryauthorization_v1beta1_keywords.py | 19 +- synth.metadata | 6 +- tests/__init__.py | 15 + tests/unit/__init__.py | 15 + tests/unit/gapic/__init__.py | 15 + .../binaryauthorization_v1beta1/__init__.py | 1 - ...st_binauthz_management_service_v1_beta1.py | 353 ++++++++++++------ 25 files changed, 666 insertions(+), 353 deletions(-) create mode 100644 google/cloud/binaryauthorization_v1beta1/gapic_metadata.json create mode 100644 tests/__init__.py create mode 100644 tests/unit/__init__.py create mode 100644 tests/unit/gapic/__init__.py diff --git a/.coveragerc b/.coveragerc index 5ff8242..95c4014 100644 --- a/.coveragerc +++ b/.coveragerc @@ -2,7 +2,6 @@ branch = True [report] -fail_under = 100 show_missing = True omit = google/cloud/binaryauthorization/__init__.py diff --git a/docs/binaryauthorization_v1beta1/binauthz_management_service_v1_beta1.rst b/docs/binaryauthorization_v1beta1/binauthz_management_service_v1_beta1.rst index 5868c89..22016d0 100644 --- a/docs/binaryauthorization_v1beta1/binauthz_management_service_v1_beta1.rst +++ b/docs/binaryauthorization_v1beta1/binauthz_management_service_v1_beta1.rst @@ -5,7 +5,6 @@ BinauthzManagementServiceV1Beta1 :members: :inherited-members: - .. automodule:: google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.pagers :members: :inherited-members: diff --git a/docs/binaryauthorization_v1beta1/services.rst b/docs/binaryauthorization_v1beta1/services.rst index e96610a..6366869 100644 --- a/docs/binaryauthorization_v1beta1/services.rst +++ b/docs/binaryauthorization_v1beta1/services.rst @@ -3,4 +3,4 @@ Services for Google Cloud Binaryauthorization v1beta1 API .. toctree:: :maxdepth: 2 - binauthz_management_service_v1_beta1 +binauthz_management_service_v1_beta1 diff --git a/google/cloud/binaryauthorization/__init__.py b/google/cloud/binaryauthorization/__init__.py index f082bea..970cae4 100644 --- a/google/cloud/binaryauthorization/__init__.py +++ b/google/cloud/binaryauthorization/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/google/cloud/binaryauthorization_v1beta1/__init__.py b/google/cloud/binaryauthorization_v1beta1/__init__.py index 5f14b9c..e66cf90 100644 --- a/google/cloud/binaryauthorization_v1beta1/__init__.py +++ b/google/cloud/binaryauthorization_v1beta1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,6 +17,7 @@ from .services.binauthz_management_service_v1_beta1 import ( BinauthzManagementServiceV1Beta1Client, ) + from .types.resources import AdmissionRule from .types.resources import AdmissionWhitelistPattern from .types.resources import Attestor @@ -34,7 +34,6 @@ from .types.service import UpdateAttestorRequest from .types.service import UpdatePolicyRequest - __all__ = ( "AdmissionRule", "AdmissionWhitelistPattern", diff --git a/google/cloud/binaryauthorization_v1beta1/gapic_metadata.json b/google/cloud/binaryauthorization_v1beta1/gapic_metadata.json new file mode 100644 index 0000000..8e56955 --- /dev/null +++ b/google/cloud/binaryauthorization_v1beta1/gapic_metadata.json @@ -0,0 +1,93 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.binaryauthorization_v1beta1", + "protoPackage": "google.cloud.binaryauthorization.v1beta1", + "schema": "1.0", + "services": { + "BinauthzManagementServiceV1Beta1": { + "clients": { + "grpc": { + "libraryClient": "BinauthzManagementServiceV1Beta1Client", + "rpcs": { + "CreateAttestor": { + "methods": [ + "create_attestor" + ] + }, + "DeleteAttestor": { + "methods": [ + "delete_attestor" + ] + }, + "GetAttestor": { + "methods": [ + "get_attestor" + ] + }, + "GetPolicy": { + "methods": [ + "get_policy" + ] + }, + "ListAttestors": { + "methods": [ + "list_attestors" + ] + }, + "UpdateAttestor": { + "methods": [ + "update_attestor" + ] + }, + "UpdatePolicy": { + "methods": [ + "update_policy" + ] + } + } + }, + "grpc-async": { + "libraryClient": "BinauthzManagementServiceV1Beta1AsyncClient", + "rpcs": { + "CreateAttestor": { + "methods": [ + "create_attestor" + ] + }, + "DeleteAttestor": { + "methods": [ + "delete_attestor" + ] + }, + "GetAttestor": { + "methods": [ + "get_attestor" + ] + }, + "GetPolicy": { + "methods": [ + "get_policy" + ] + }, + "ListAttestors": { + "methods": [ + "list_attestors" + ] + }, + "UpdateAttestor": { + "methods": [ + "update_attestor" + ] + }, + "UpdatePolicy": { + "methods": [ + "update_policy" + ] + } + } + } + } + } + } +} diff --git a/google/cloud/binaryauthorization_v1beta1/services/__init__.py b/google/cloud/binaryauthorization_v1beta1/services/__init__.py index 42ffdf2..4de6597 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/__init__.py +++ b/google/cloud/binaryauthorization_v1beta1/services/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/__init__.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/__init__.py index f832d0c..e133615 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/__init__.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .client import BinauthzManagementServiceV1Beta1Client from .async_client import BinauthzManagementServiceV1Beta1AsyncClient diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py index c8c2474..89229e8 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict import functools import re @@ -34,7 +32,6 @@ from google.cloud.binaryauthorization_v1beta1.types import resources from google.cloud.binaryauthorization_v1beta1.types import service from google.protobuf import timestamp_pb2 as timestamp # type: ignore - from .transports.base import ( BinauthzManagementServiceV1Beta1Transport, DEFAULT_CLIENT_INFO, @@ -68,35 +65,30 @@ class BinauthzManagementServiceV1Beta1AsyncClient: parse_policy_path = staticmethod( BinauthzManagementServiceV1Beta1Client.parse_policy_path ) - common_billing_account_path = staticmethod( BinauthzManagementServiceV1Beta1Client.common_billing_account_path ) parse_common_billing_account_path = staticmethod( BinauthzManagementServiceV1Beta1Client.parse_common_billing_account_path ) - common_folder_path = staticmethod( BinauthzManagementServiceV1Beta1Client.common_folder_path ) parse_common_folder_path = staticmethod( BinauthzManagementServiceV1Beta1Client.parse_common_folder_path ) - common_organization_path = staticmethod( BinauthzManagementServiceV1Beta1Client.common_organization_path ) parse_common_organization_path = staticmethod( BinauthzManagementServiceV1Beta1Client.parse_common_organization_path ) - common_project_path = staticmethod( BinauthzManagementServiceV1Beta1Client.common_project_path ) parse_common_project_path = staticmethod( BinauthzManagementServiceV1Beta1Client.parse_common_project_path ) - common_location_path = staticmethod( BinauthzManagementServiceV1Beta1Client.common_location_path ) @@ -192,7 +184,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = BinauthzManagementServiceV1Beta1Client( credentials=credentials, transport=transport, @@ -225,7 +216,8 @@ async def get_policy( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.GetPolicyRequest`): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.GetPolicy][]. name (:class:`str`): Required. The resource name of the @@ -235,7 +227,6 @@ async def get_policy( This corresponds to the ``name`` 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. @@ -262,7 +253,6 @@ async def get_policy( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -315,7 +305,8 @@ async def update_policy( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.UpdatePolicyRequest`): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.UpdatePolicy][]. policy_ (:class:`google.cloud.binaryauthorization_v1beta1.types.Policy`): Required. A new or updated @@ -328,7 +319,6 @@ async def update_policy( This corresponds to the ``policy_`` 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. @@ -355,7 +345,6 @@ async def update_policy( # If we have keyword arguments corresponding to fields on the # request, apply these. - if policy_ is not None: request.policy_ = policy_ @@ -413,7 +402,8 @@ async def create_attestor( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.CreateAttestorRequest`): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.CreateAttestor][]. parent (:class:`str`): Required. The parent of this @@ -441,7 +431,6 @@ async def create_attestor( This corresponds to the ``attestor`` 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. @@ -469,7 +458,6 @@ async def create_attestor( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if attestor_id is not None: @@ -514,7 +502,8 @@ async def get_attestor( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.GetAttestorRequest`): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.GetAttestor][]. name (:class:`str`): Required. The name of the @@ -524,7 +513,6 @@ async def get_attestor( This corresponds to the ``name`` 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. @@ -552,7 +540,6 @@ async def get_attestor( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -602,7 +589,8 @@ async def update_attestor( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.UpdateAttestorRequest`): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.UpdateAttestor][]. attestor (:class:`google.cloud.binaryauthorization_v1beta1.types.Attestor`): Required. The updated @@ -615,7 +603,6 @@ async def update_attestor( This corresponds to the ``attestor`` 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. @@ -643,7 +630,6 @@ async def update_attestor( # If we have keyword arguments corresponding to fields on the # request, apply these. - if attestor is not None: request.attestor = attestor @@ -693,7 +679,8 @@ async def list_attestors( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.ListAttestorsRequest`): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.ListAttestors][]. parent (:class:`str`): Required. The resource name of the project associated @@ -704,7 +691,6 @@ async def list_attestors( This corresponds to the ``parent`` 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. @@ -734,7 +720,6 @@ async def list_attestors( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -790,7 +775,8 @@ async def delete_attestor( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.DeleteAttestorRequest`): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.DeleteAttestor][]. name (:class:`str`): Required. The name of the @@ -800,7 +786,6 @@ async def delete_attestor( This corresponds to the ``name`` 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. @@ -821,7 +806,6 @@ async def delete_attestor( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py index 4dbbd25..e836d8c 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from distutils import util import os @@ -38,7 +36,6 @@ from google.cloud.binaryauthorization_v1beta1.types import resources from google.cloud.binaryauthorization_v1beta1.types import service from google.protobuf import timestamp_pb2 as timestamp # type: ignore - from .transports.base import ( BinauthzManagementServiceV1Beta1Transport, DEFAULT_CLIENT_INFO, @@ -398,7 +395,8 @@ def get_policy( Args: request (google.cloud.binaryauthorization_v1beta1.types.GetPolicyRequest): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.GetPolicy][]. name (str): Required. The resource name of the @@ -408,7 +406,6 @@ def get_policy( This corresponds to the ``name`` 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. @@ -437,10 +434,8 @@ def get_policy( # there are no flattened fields. if not isinstance(request, service.GetPolicyRequest): request = service.GetPolicyRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -480,7 +475,8 @@ def update_policy( Args: request (google.cloud.binaryauthorization_v1beta1.types.UpdatePolicyRequest): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.UpdatePolicy][]. policy_ (google.cloud.binaryauthorization_v1beta1.types.Policy): Required. A new or updated @@ -493,7 +489,6 @@ def update_policy( This corresponds to the ``policy_`` 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. @@ -522,10 +517,8 @@ def update_policy( # there are no flattened fields. if not isinstance(request, service.UpdatePolicyRequest): request = service.UpdatePolicyRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if policy_ is not None: request.policy_ = policy_ @@ -570,7 +563,8 @@ def create_attestor( Args: request (google.cloud.binaryauthorization_v1beta1.types.CreateAttestorRequest): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.CreateAttestor][]. parent (str): Required. The parent of this @@ -598,7 +592,6 @@ def create_attestor( This corresponds to the ``attestor`` 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. @@ -628,10 +621,8 @@ def create_attestor( # there are no flattened fields. if not isinstance(request, service.CreateAttestorRequest): request = service.CreateAttestorRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if attestor_id is not None: @@ -672,7 +663,8 @@ def get_attestor( Args: request (google.cloud.binaryauthorization_v1beta1.types.GetAttestorRequest): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.GetAttestor][]. name (str): Required. The name of the @@ -682,7 +674,6 @@ def get_attestor( This corresponds to the ``name`` 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. @@ -712,10 +703,8 @@ def get_attestor( # there are no flattened fields. if not isinstance(request, service.GetAttestorRequest): request = service.GetAttestorRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -752,7 +741,8 @@ def update_attestor( Args: request (google.cloud.binaryauthorization_v1beta1.types.UpdateAttestorRequest): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.UpdateAttestor][]. attestor (google.cloud.binaryauthorization_v1beta1.types.Attestor): Required. The updated @@ -765,7 +755,6 @@ def update_attestor( This corresponds to the ``attestor`` 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. @@ -795,10 +784,8 @@ def update_attestor( # there are no flattened fields. if not isinstance(request, service.UpdateAttestorRequest): request = service.UpdateAttestorRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if attestor is not None: request.attestor = attestor @@ -835,7 +822,8 @@ def list_attestors( Args: request (google.cloud.binaryauthorization_v1beta1.types.ListAttestorsRequest): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.ListAttestors][]. parent (str): Required. The resource name of the project associated @@ -846,7 +834,6 @@ def list_attestors( This corresponds to the ``parent`` 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. @@ -878,10 +865,8 @@ def list_attestors( # there are no flattened fields. if not isinstance(request, service.ListAttestorsRequest): request = service.ListAttestorsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -924,7 +909,8 @@ def delete_attestor( Args: request (google.cloud.binaryauthorization_v1beta1.types.DeleteAttestorRequest): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.DeleteAttestor][]. name (str): Required. The name of the @@ -934,7 +920,6 @@ def delete_attestor( This corresponds to the ``name`` 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. @@ -957,10 +942,8 @@ def delete_attestor( # there are no flattened fields. if not isinstance(request, service.DeleteAttestorRequest): request = service.DeleteAttestorRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/pagers.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/pagers.py index 42c4659..9aecf4b 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/pagers.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/pagers.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from typing import ( Any, AsyncIterable, diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/__init__.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/__init__.py index 78aef3f..bf3c24d 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/__init__.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from typing import Dict, Type diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/base.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/base.py index 9bc0a22..c785aa1 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/base.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/base.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,12 +13,13 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import abc -import typing +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import packaging.version import pkg_resources from google import auth # type: ignore +import google.api_core # type: ignore from google.api_core import exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore @@ -29,7 +29,6 @@ from google.cloud.binaryauthorization_v1beta1.types import service from google.protobuf import empty_pb2 as empty # type: ignore - try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=pkg_resources.get_distribution( @@ -39,27 +38,41 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +try: + # google.auth.__version__ was added in 1.26.0 + _GOOGLE_AUTH_VERSION = auth.__version__ +except AttributeError: + try: # try pkg_resources if it is available + _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version + except pkg_resources.DistributionNotFound: # pragma: NO COVER + _GOOGLE_AUTH_VERSION = None + +_API_CORE_VERSION = google.api_core.__version__ + class BinauthzManagementServiceV1Beta1Transport(abc.ABC): """Abstract transport class for BinauthzManagementServiceV1Beta1.""" AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + DEFAULT_HOST: str = "binaryauthorization.googleapis.com" + def __init__( self, *, - host: str = "binaryauthorization.googleapis.com", + host: str = DEFAULT_HOST, credentials: credentials.Credentials = None, - credentials_file: typing.Optional[str] = None, - scopes: typing.Optional[typing.Sequence[str]] = AUTH_SCOPES, - quota_project_id: typing.Optional[str] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, **kwargs, ) -> None: """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -68,7 +81,7 @@ def __init__( credentials_file (Optional[str]): A file with credentials that can be loaded with :func:`google.auth.load_credentials_from_file`. This argument is mutually exclusive with credentials. - scope (Optional[Sequence[str]]): A list of scopes. + scopes (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -82,6 +95,8 @@ def __init__( host += ":443" self._host = host + scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + # Save the scopes. self._scopes = scopes or self.AUTH_SCOPES @@ -94,17 +109,62 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=self._scopes, quota_project_id=quota_project_id + credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=self._scopes, quota_project_id=quota_project_id + **scopes_kwargs, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials + # TODO(busunkim): These two class methods are in the base transport + # to avoid duplicating code across the transport classes. These functions + # should be deleted once the minimum required versions of google-api-core + # and google-auth are increased. + + # TODO: Remove this function once google-auth >= 1.25.0 is required + @classmethod + def _get_scopes_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Optional[Sequence[str]]]: + """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" + + scopes_kwargs = {} + + if _GOOGLE_AUTH_VERSION and ( + packaging.version.parse(_GOOGLE_AUTH_VERSION) + >= packaging.version.parse("1.25.0") + ): + scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} + else: + scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} + + return scopes_kwargs + + # TODO: Remove this function once google-api-core >= 1.26.0 is required + @classmethod + def _get_self_signed_jwt_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Union[Optional[Sequence[str]], str]]: + """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" + + self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} + + if _API_CORE_VERSION and ( + packaging.version.parse(_API_CORE_VERSION) + >= packaging.version.parse("1.26.0") + ): + self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES + self_signed_jwt_kwargs["scopes"] = scopes + self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST + else: + self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES + + return self_signed_jwt_kwargs + def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -200,66 +260,61 @@ def _prep_wrapped_messages(self, client_info): @property def get_policy( self, - ) -> typing.Callable[ - [service.GetPolicyRequest], - typing.Union[resources.Policy, typing.Awaitable[resources.Policy]], + ) -> Callable[ + [service.GetPolicyRequest], Union[resources.Policy, Awaitable[resources.Policy]] ]: raise NotImplementedError() @property def update_policy( self, - ) -> typing.Callable[ + ) -> Callable[ [service.UpdatePolicyRequest], - typing.Union[resources.Policy, typing.Awaitable[resources.Policy]], + Union[resources.Policy, Awaitable[resources.Policy]], ]: raise NotImplementedError() @property def create_attestor( self, - ) -> typing.Callable[ + ) -> Callable[ [service.CreateAttestorRequest], - typing.Union[resources.Attestor, typing.Awaitable[resources.Attestor]], + Union[resources.Attestor, Awaitable[resources.Attestor]], ]: raise NotImplementedError() @property def get_attestor( self, - ) -> typing.Callable[ + ) -> Callable[ [service.GetAttestorRequest], - typing.Union[resources.Attestor, typing.Awaitable[resources.Attestor]], + Union[resources.Attestor, Awaitable[resources.Attestor]], ]: raise NotImplementedError() @property def update_attestor( self, - ) -> typing.Callable[ + ) -> Callable[ [service.UpdateAttestorRequest], - typing.Union[resources.Attestor, typing.Awaitable[resources.Attestor]], + Union[resources.Attestor, Awaitable[resources.Attestor]], ]: raise NotImplementedError() @property def list_attestors( self, - ) -> typing.Callable[ + ) -> Callable[ [service.ListAttestorsRequest], - typing.Union[ - service.ListAttestorsResponse, - typing.Awaitable[service.ListAttestorsResponse], - ], + Union[service.ListAttestorsResponse, Awaitable[service.ListAttestorsResponse]], ]: raise NotImplementedError() @property def delete_attestor( self, - ) -> typing.Callable[ - [service.DeleteAttestorRequest], - typing.Union[empty.Empty, typing.Awaitable[empty.Empty]], + ) -> Callable[ + [service.DeleteAttestorRequest], Union[empty.Empty, Awaitable[empty.Empty]] ]: raise NotImplementedError() diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py index e2a2f5b..f6095cf 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,9 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple +from typing import Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import grpc_helpers # type: ignore from google.api_core import gapic_v1 # type: ignore @@ -29,7 +27,6 @@ from google.cloud.binaryauthorization_v1beta1.types import resources from google.cloud.binaryauthorization_v1beta1.types import service from google.protobuf import empty_pb2 as empty # type: ignore - from .base import BinauthzManagementServiceV1Beta1Transport, DEFAULT_CLIENT_INFO @@ -74,7 +71,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -215,13 +213,15 @@ def create_channel( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -233,7 +233,9 @@ def grpc_channel(self) -> grpc.Channel: @property def get_policy(self) -> Callable[[service.GetPolicyRequest], resources.Policy]: - r"""Return a callable for the get policy method over gRPC. + r"""Return a callable for the + get policy + method over gRPC. A [policy][google.cloud.binaryauthorization.v1beta1.Policy] specifies the @@ -271,7 +273,9 @@ def get_policy(self) -> Callable[[service.GetPolicyRequest], resources.Policy]: def update_policy( self, ) -> Callable[[service.UpdatePolicyRequest], resources.Policy]: - r"""Return a callable for the update policy method over gRPC. + r"""Return a callable for the + update policy + method over gRPC. Creates or updates a project's [policy][google.cloud.binaryauthorization.v1beta1.Policy], and @@ -304,7 +308,9 @@ def update_policy( def create_attestor( self, ) -> Callable[[service.CreateAttestorRequest], resources.Attestor]: - r"""Return a callable for the create attestor method over gRPC. + r"""Return a callable for the + create attestor + method over gRPC. Creates an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor], @@ -338,7 +344,9 @@ def create_attestor( def get_attestor( self, ) -> Callable[[service.GetAttestorRequest], resources.Attestor]: - r"""Return a callable for the get attestor method over gRPC. + r"""Return a callable for the + get attestor + method over gRPC. Gets an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor]. @@ -368,7 +376,9 @@ def get_attestor( def update_attestor( self, ) -> Callable[[service.UpdateAttestorRequest], resources.Attestor]: - r"""Return a callable for the update attestor method over gRPC. + r"""Return a callable for the + update attestor + method over gRPC. Updates an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor]. @@ -398,7 +408,9 @@ def update_attestor( def list_attestors( self, ) -> Callable[[service.ListAttestorsRequest], service.ListAttestorsResponse]: - r"""Return a callable for the list attestors method over gRPC. + r"""Return a callable for the + list attestors + method over gRPC. Lists [attestors][google.cloud.binaryauthorization.v1beta1.Attestor]. @@ -424,7 +436,9 @@ def list_attestors( @property def delete_attestor(self) -> Callable[[service.DeleteAttestorRequest], empty.Empty]: - r"""Return a callable for the delete attestor method over gRPC. + r"""Return a callable for the + delete attestor + method over gRPC. Deletes an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor]. diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py index 4b621da..3f7135e 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,15 +13,15 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import gapic_v1 # type: ignore from google.api_core import grpc_helpers_async # type: ignore from google import auth # type: ignore from google.auth import credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -30,7 +29,6 @@ from google.cloud.binaryauthorization_v1beta1.types import resources from google.cloud.binaryauthorization_v1beta1.types import service from google.protobuf import empty_pb2 as empty # type: ignore - from .base import BinauthzManagementServiceV1Beta1Transport, DEFAULT_CLIENT_INFO from .grpc import BinauthzManagementServiceV1Beta1GrpcTransport @@ -90,13 +88,15 @@ def create_channel( Returns: aio.Channel: A gRPC AsyncIO channel object. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -118,7 +118,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -176,7 +177,6 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - else: if api_mtls_endpoint: host = api_mtls_endpoint @@ -239,7 +239,9 @@ def grpc_channel(self) -> aio.Channel: def get_policy( self, ) -> Callable[[service.GetPolicyRequest], Awaitable[resources.Policy]]: - r"""Return a callable for the get policy method over gRPC. + r"""Return a callable for the + get policy + method over gRPC. A [policy][google.cloud.binaryauthorization.v1beta1.Policy] specifies the @@ -277,7 +279,9 @@ def get_policy( def update_policy( self, ) -> Callable[[service.UpdatePolicyRequest], Awaitable[resources.Policy]]: - r"""Return a callable for the update policy method over gRPC. + r"""Return a callable for the + update policy + method over gRPC. Creates or updates a project's [policy][google.cloud.binaryauthorization.v1beta1.Policy], and @@ -310,7 +314,9 @@ def update_policy( def create_attestor( self, ) -> Callable[[service.CreateAttestorRequest], Awaitable[resources.Attestor]]: - r"""Return a callable for the create attestor method over gRPC. + r"""Return a callable for the + create attestor + method over gRPC. Creates an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor], @@ -344,7 +350,9 @@ def create_attestor( def get_attestor( self, ) -> Callable[[service.GetAttestorRequest], Awaitable[resources.Attestor]]: - r"""Return a callable for the get attestor method over gRPC. + r"""Return a callable for the + get attestor + method over gRPC. Gets an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor]. @@ -374,7 +382,9 @@ def get_attestor( def update_attestor( self, ) -> Callable[[service.UpdateAttestorRequest], Awaitable[resources.Attestor]]: - r"""Return a callable for the update attestor method over gRPC. + r"""Return a callable for the + update attestor + method over gRPC. Updates an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor]. @@ -406,7 +416,9 @@ def list_attestors( ) -> Callable[ [service.ListAttestorsRequest], Awaitable[service.ListAttestorsResponse] ]: - r"""Return a callable for the list attestors method over gRPC. + r"""Return a callable for the + list attestors + method over gRPC. Lists [attestors][google.cloud.binaryauthorization.v1beta1.Attestor]. @@ -434,7 +446,9 @@ def list_attestors( def delete_attestor( self, ) -> Callable[[service.DeleteAttestorRequest], Awaitable[empty.Empty]]: - r"""Return a callable for the delete attestor method over gRPC. + r"""Return a callable for the + delete attestor + method over gRPC. Deletes an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor]. diff --git a/google/cloud/binaryauthorization_v1beta1/types/__init__.py b/google/cloud/binaryauthorization_v1beta1/types/__init__.py index b4424d4..122112d 100644 --- a/google/cloud/binaryauthorization_v1beta1/types/__init__.py +++ b/google/cloud/binaryauthorization_v1beta1/types/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .resources import ( AdmissionRule, AdmissionWhitelistPattern, diff --git a/google/cloud/binaryauthorization_v1beta1/types/resources.py b/google/cloud/binaryauthorization_v1beta1/types/resources.py index 7866476..f2fb4fd 100644 --- a/google/cloud/binaryauthorization_v1beta1/types/resources.py +++ b/google/cloud/binaryauthorization_v1beta1/types/resources.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,23 +13,21 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.protobuf import timestamp_pb2 as timestamp # type: ignore __protobuf__ = proto.module( - package="google.cloud.binaryauthorization.v1beta1", + package='google.cloud.binaryauthorization.v1beta1', manifest={ - "Policy", - "AdmissionWhitelistPattern", - "AdmissionRule", - "Attestor", - "UserOwnedDrydockNote", - "PkixPublicKey", - "AttestorPublicKey", + 'Policy', + 'AdmissionWhitelistPattern', + 'AdmissionRule', + 'Attestor', + 'UserOwnedDrydockNote', + 'PkixPublicKey', + 'AttestorPublicKey', }, ) @@ -76,34 +73,46 @@ class Policy(proto.Message): Output only. Time when the policy was last updated. """ - class GlobalPolicyEvaluationMode(proto.Enum): r"""""" GLOBAL_POLICY_EVALUATION_MODE_UNSPECIFIED = 0 ENABLE = 1 DISABLE = 2 - name = proto.Field(proto.STRING, number=1) - - description = proto.Field(proto.STRING, number=6) - + name = proto.Field( + proto.STRING, + number=1, + ) + description = proto.Field( + proto.STRING, + number=6, + ) global_policy_evaluation_mode = proto.Field( - proto.ENUM, number=7, enum=GlobalPolicyEvaluationMode, + proto.ENUM, + number=7, + enum=GlobalPolicyEvaluationMode, ) - admission_whitelist_patterns = proto.RepeatedField( - proto.MESSAGE, number=2, message="AdmissionWhitelistPattern", + proto.MESSAGE, + number=2, + message='AdmissionWhitelistPattern', ) - cluster_admission_rules = proto.MapField( - proto.STRING, proto.MESSAGE, number=3, message="AdmissionRule", + proto.STRING, + proto.MESSAGE, + number=3 + message='AdmissionRule', ) - default_admission_rule = proto.Field( - proto.MESSAGE, number=4, message="AdmissionRule", + proto.MESSAGE, + number=4, + message='AdmissionRule', + ) + update_time = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp.Timestamp, ) - - update_time = proto.Field(proto.MESSAGE, number=5, message=timestamp.Timestamp,) class AdmissionWhitelistPattern(proto.Message): @@ -120,7 +129,10 @@ class AdmissionWhitelistPattern(proto.Message): ``registry/`` part. """ - name_pattern = proto.Field(proto.STRING, number=1) + name_pattern = proto.Field( + proto.STRING, + number=1, + ) class AdmissionRule(proto.Message): @@ -156,7 +168,6 @@ class AdmissionRule(proto.Message): Required. The action when a pod creation is denied by the admission rule. """ - class EvaluationMode(proto.Enum): r"""""" EVALUATION_MODE_UNSPECIFIED = 0 @@ -172,11 +183,20 @@ class EnforcementMode(proto.Enum): ENFORCED_BLOCK_AND_AUDIT_LOG = 1 DRYRUN_AUDIT_LOG_ONLY = 2 - evaluation_mode = proto.Field(proto.ENUM, number=1, enum=EvaluationMode,) - - require_attestations_by = proto.RepeatedField(proto.STRING, number=2) - - enforcement_mode = proto.Field(proto.ENUM, number=3, enum=EnforcementMode,) + evaluation_mode = proto.Field( + proto.ENUM, + number=1, + enum=EvaluationMode, + ) + require_attestations_by = proto.RepeatedField( + proto.STRING, + number=2, + ) + enforcement_mode = proto.Field( + proto.ENUM, + number=3, + enum=EnforcementMode, + ) class Attestor(proto.Message): @@ -199,15 +219,25 @@ class Attestor(proto.Message): updated. """ - name = proto.Field(proto.STRING, number=1) - - description = proto.Field(proto.STRING, number=6) - + name = proto.Field( + proto.STRING, + number=1, + ) + description = proto.Field( + proto.STRING, + number=6, + ) user_owned_drydock_note = proto.Field( - proto.MESSAGE, number=3, oneof="attestor_type", message="UserOwnedDrydockNote", + proto.MESSAGE, + number=3, + oneof='attestor_type', + message='UserOwnedDrydockNote', + ) + update_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp.Timestamp, ) - - update_time = proto.Field(proto.MESSAGE, number=4, message=timestamp.Timestamp,) class UserOwnedDrydockNote(proto.Message): @@ -251,13 +281,19 @@ class UserOwnedDrydockNote(proto.Message): email based on a different naming pattern. """ - note_reference = proto.Field(proto.STRING, number=1) - + note_reference = proto.Field( + proto.STRING, + number=1, + ) public_keys = proto.RepeatedField( - proto.MESSAGE, number=2, message="AttestorPublicKey", + proto.MESSAGE, + number=2, + message='AttestorPublicKey', + ) + delegation_service_account_email = proto.Field( + proto.STRING, + number=3, ) - - delegation_service_account_email = proto.Field(proto.STRING, number=3) class PkixPublicKey(proto.Message): @@ -277,7 +313,6 @@ class PkixPublicKey(proto.Message): ``public_key_pem`` (i.e. this algorithm must match that of the public key). """ - class SignatureAlgorithm(proto.Enum): r"""Represents a signature algorithm and other information necessary to verify signatures with a given public key. This is @@ -300,9 +335,15 @@ class SignatureAlgorithm(proto.Enum): ECDSA_P384_SHA384 = 10 ECDSA_P521_SHA512 = 11 - public_key_pem = proto.Field(proto.STRING, number=1) - - signature_algorithm = proto.Field(proto.ENUM, number=2, enum=SignatureAlgorithm,) + public_key_pem = proto.Field( + proto.STRING, + number=1, + ) + signature_algorithm = proto.Field( + proto.ENUM, + number=2, + enum=SignatureAlgorithm, + ) class AttestorPublicKey(proto.Message): @@ -341,16 +382,24 @@ class AttestorPublicKey(proto.Message): public key. """ - comment = proto.Field(proto.STRING, number=1) - - id = proto.Field(proto.STRING, number=2) - + comment = proto.Field( + proto.STRING, + number=1, + ) + id = proto.Field( + proto.STRING, + number=2, + ) ascii_armored_pgp_public_key = proto.Field( - proto.STRING, number=3, oneof="public_key" + proto.STRING, + number=3, + oneof='public_key', ) - pkix_public_key = proto.Field( - proto.MESSAGE, number=5, oneof="public_key", message="PkixPublicKey", + proto.MESSAGE, + number=5, + oneof='public_key', + message='PkixPublicKey', ) diff --git a/google/cloud/binaryauthorization_v1beta1/types/service.py b/google/cloud/binaryauthorization_v1beta1/types/service.py index c77d251..95e8f7f 100644 --- a/google/cloud/binaryauthorization_v1beta1/types/service.py +++ b/google/cloud/binaryauthorization_v1beta1/types/service.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.binaryauthorization_v1beta1.types import resources @@ -38,7 +35,6 @@ class GetPolicyRequest(proto.Message): r"""Request message for [BinauthzManagementService.GetPolicy][]. - Attributes: name (str): Required. The resource name of the @@ -46,12 +42,11 @@ class GetPolicyRequest(proto.Message): retrieve, in the format ``projects/*/policy``. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class UpdatePolicyRequest(proto.Message): r"""Request message for [BinauthzManagementService.UpdatePolicy][]. - Attributes: policy_ (google.cloud.binaryauthorization_v1beta1.types.Policy): Required. A new or updated @@ -67,7 +62,6 @@ class UpdatePolicyRequest(proto.Message): class CreateAttestorRequest(proto.Message): r"""Request message for [BinauthzManagementService.CreateAttestor][]. - Attributes: parent (str): Required. The parent of this @@ -85,16 +79,13 @@ class CreateAttestorRequest(proto.Message): ``projects/*/attestors/*``. """ - parent = proto.Field(proto.STRING, number=1) - - attestor_id = proto.Field(proto.STRING, number=2) - + parent = proto.Field(proto.STRING, number=1,) + attestor_id = proto.Field(proto.STRING, number=2,) attestor = proto.Field(proto.MESSAGE, number=3, message=resources.Attestor,) class GetAttestorRequest(proto.Message): r"""Request message for [BinauthzManagementService.GetAttestor][]. - Attributes: name (str): Required. The name of the @@ -102,12 +93,11 @@ class GetAttestorRequest(proto.Message): to retrieve, in the format ``projects/*/attestors/*``. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class UpdateAttestorRequest(proto.Message): r"""Request message for [BinauthzManagementService.UpdateAttestor][]. - Attributes: attestor (google.cloud.binaryauthorization_v1beta1.types.Attestor): Required. The updated @@ -123,7 +113,6 @@ class UpdateAttestorRequest(proto.Message): class ListAttestorsRequest(proto.Message): r"""Request message for [BinauthzManagementService.ListAttestors][]. - Attributes: parent (str): Required. The resource name of the project associated with @@ -142,16 +131,13 @@ class ListAttestorsRequest(proto.Message): method. """ - parent = proto.Field(proto.STRING, number=1) - - page_size = proto.Field(proto.INT32, number=2) - - page_token = proto.Field(proto.STRING, number=3) + parent = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=2,) + page_token = proto.Field(proto.STRING, number=3,) class ListAttestorsResponse(proto.Message): r"""Response message for [BinauthzManagementService.ListAttestors][]. - Attributes: attestors (Sequence[google.cloud.binaryauthorization_v1beta1.types.Attestor]): The list of @@ -171,13 +157,11 @@ def raw_page(self): attestors = proto.RepeatedField( proto.MESSAGE, number=1, message=resources.Attestor, ) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class DeleteAttestorRequest(proto.Message): r"""Request message for [BinauthzManagementService.DeleteAttestor][]. - Attributes: name (str): Required. The name of the @@ -185,7 +169,7 @@ class DeleteAttestorRequest(proto.Message): to delete, in the format ``projects/*/attestors/*``. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/scripts/fixup_binaryauthorization_v1beta1_keywords.py b/scripts/fixup_binaryauthorization_v1beta1_keywords.py index 56d9bd4..f6299f4 100644 --- a/scripts/fixup_binaryauthorization_v1beta1_keywords.py +++ b/scripts/fixup_binaryauthorization_v1beta1_keywords.py @@ -1,6 +1,5 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import argparse import os import libcst as cst @@ -41,14 +39,13 @@ def partition( class binaryauthorizationCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'create_attestor': ('parent', 'attestor_id', 'attestor', ), - 'delete_attestor': ('name', ), - 'get_attestor': ('name', ), - 'get_policy': ('name', ), - 'list_attestors': ('parent', 'page_size', 'page_token', ), - 'update_attestor': ('attestor', ), - 'update_policy': ('policy_', ), - + 'create_attestor': ('parent', 'attestor_id', 'attestor', ), + 'delete_attestor': ('name', ), + 'get_attestor': ('name', ), + 'get_policy': ('name', ), + 'list_attestors': ('parent', 'page_size', 'page_token', ), + 'update_attestor': ('attestor', ), + 'update_policy': ('policy_', ), } def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: @@ -79,7 +76,7 @@ def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: value=cst.Dict([ cst.DictElement( cst.SimpleString("'{}'".format(name)), - cst.Element(value=arg.value) +cst.Element(value=arg.value) ) # Note: the args + kwargs looks silly, but keep in mind that # the control parameters had to be stripped out, and that diff --git a/synth.metadata b/synth.metadata index f9cf74d..050d164 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,15 +4,15 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/python-binary-authorization.git", - "sha": "996f5010afd4372d625a9accc57647bac46770a8" + "sha": "82b3583c8dbc897dbb192ffc2051de5169d934c2" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "2490be32f08cccc870862ea86920f58325795c89", - "internalRef": "366826395" + "sha": "56fc6d43fed71188d7e18f3ca003544646c4ab35", + "internalRef": "366346972" } } ], diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..4de6597 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py new file mode 100644 index 0000000..4de6597 --- /dev/null +++ b/tests/unit/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/tests/unit/gapic/__init__.py b/tests/unit/gapic/__init__.py new file mode 100644 index 0000000..4de6597 --- /dev/null +++ b/tests/unit/gapic/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/tests/unit/gapic/binaryauthorization_v1beta1/__init__.py b/tests/unit/gapic/binaryauthorization_v1beta1/__init__.py index 42ffdf2..4de6597 100644 --- a/tests/unit/gapic/binaryauthorization_v1beta1/__init__.py +++ b/tests/unit/gapic/binaryauthorization_v1beta1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py b/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py index cb13870..4ccb375 100644 --- a/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py +++ b/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import os import mock +import packaging.version import grpc from grpc.experimental import aio @@ -24,6 +23,7 @@ import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule + from google import auth from google.api_core import client_options from google.api_core import exceptions @@ -44,12 +44,41 @@ from google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1 import ( transports, ) +from google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.transports.base import ( + _API_CORE_VERSION, +) +from google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.transports.base import ( + _GOOGLE_AUTH_VERSION, +) from google.cloud.binaryauthorization_v1beta1.types import resources from google.cloud.binaryauthorization_v1beta1.types import service from google.oauth2 import service_account from google.protobuf import timestamp_pb2 as timestamp # type: ignore +# TODO(busunkim): Once google-api-core >= 1.26.0 is required: +# - Delete all the api-core and auth "less than" test cases +# - Delete these pytest markers (Make the "greater than or equal to" tests the default). +requires_google_auth_lt_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), + reason="This test requires google-auth < 1.25.0", +) +requires_google_auth_gte_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), + reason="This test requires google-auth >= 1.25.0", +) + +requires_api_core_lt_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), + reason="This test requires google-api-core < 1.26.0", +) + +requires_api_core_gte_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), + reason="This test requires google-api-core >= 1.26.0", +) + + def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -516,23 +545,17 @@ def test_get_policy(transport: str = "grpc", request_type=service.GetPolicyReque description="description_value", global_policy_evaluation_mode=resources.Policy.GlobalPolicyEvaluationMode.ENABLE, ) - response = client.get_policy(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.GetPolicyRequest() # Establish that the response is the type that we expect. - assert isinstance(response, resources.Policy) - assert response.name == "name_value" - assert response.description == "description_value" - assert ( response.global_policy_evaluation_mode == resources.Policy.GlobalPolicyEvaluationMode.ENABLE @@ -555,7 +578,6 @@ def test_get_policy_empty_call(): client.get_policy() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.GetPolicyRequest() @@ -581,22 +603,17 @@ async def test_get_policy_async( global_policy_evaluation_mode=resources.Policy.GlobalPolicyEvaluationMode.ENABLE, ) ) - response = await client.get_policy(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.GetPolicyRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.Policy) - assert response.name == "name_value" - assert response.description == "description_value" - assert ( response.global_policy_evaluation_mode == resources.Policy.GlobalPolicyEvaluationMode.ENABLE @@ -616,12 +633,12 @@ def test_get_policy_field_headers(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetPolicyRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_policy), "__call__") as call: call.return_value = resources.Policy() - client.get_policy(request) # Establish that the underlying gRPC stub method was called. @@ -643,12 +660,12 @@ async def test_get_policy_field_headers_async(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetPolicyRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_policy), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Policy()) - await client.get_policy(request) # Establish that the underlying gRPC stub method was called. @@ -670,7 +687,6 @@ def test_get_policy_flattened(): with mock.patch.object(type(client.transport.get_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Policy() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_policy(name="name_value",) @@ -679,7 +695,6 @@ def test_get_policy_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @@ -716,7 +731,6 @@ async def test_get_policy_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @@ -753,23 +767,17 @@ def test_update_policy( description="description_value", global_policy_evaluation_mode=resources.Policy.GlobalPolicyEvaluationMode.ENABLE, ) - response = client.update_policy(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdatePolicyRequest() # Establish that the response is the type that we expect. - assert isinstance(response, resources.Policy) - assert response.name == "name_value" - assert response.description == "description_value" - assert ( response.global_policy_evaluation_mode == resources.Policy.GlobalPolicyEvaluationMode.ENABLE @@ -792,7 +800,6 @@ def test_update_policy_empty_call(): client.update_policy() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdatePolicyRequest() @@ -818,22 +825,17 @@ async def test_update_policy_async( global_policy_evaluation_mode=resources.Policy.GlobalPolicyEvaluationMode.ENABLE, ) ) - response = await client.update_policy(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdatePolicyRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.Policy) - assert response.name == "name_value" - assert response.description == "description_value" - assert ( response.global_policy_evaluation_mode == resources.Policy.GlobalPolicyEvaluationMode.ENABLE @@ -853,12 +855,12 @@ def test_update_policy_field_headers(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UpdatePolicyRequest() + request.policy.name = "policy.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_policy), "__call__") as call: call.return_value = resources.Policy() - client.update_policy(request) # Establish that the underlying gRPC stub method was called. @@ -880,12 +882,12 @@ async def test_update_policy_field_headers_async(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UpdatePolicyRequest() + request.policy.name = "policy.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_policy), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Policy()) - await client.update_policy(request) # Establish that the underlying gRPC stub method was called. @@ -907,7 +909,6 @@ def test_update_policy_flattened(): with mock.patch.object(type(client.transport.update_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Policy() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.update_policy(policy_=resources.Policy(name="name_value"),) @@ -916,7 +917,6 @@ def test_update_policy_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].policy_ == resources.Policy(name="name_value") @@ -955,7 +955,6 @@ async def test_update_policy_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].policy_ == resources.Policy(name="name_value") @@ -994,21 +993,16 @@ def test_create_attestor( note_reference="note_reference_value" ), ) - response = client.create_attestor(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.CreateAttestorRequest() # Establish that the response is the type that we expect. - assert isinstance(response, resources.Attestor) - assert response.name == "name_value" - assert response.description == "description_value" @@ -1028,7 +1022,6 @@ def test_create_attestor_empty_call(): client.create_attestor() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.CreateAttestorRequest() @@ -1050,20 +1043,16 @@ async def test_create_attestor_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.Attestor(name="name_value", description="description_value",) ) - response = await client.create_attestor(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.CreateAttestorRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.Attestor) - assert response.name == "name_value" - assert response.description == "description_value" @@ -1080,12 +1069,12 @@ def test_create_attestor_field_headers(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.CreateAttestorRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_attestor), "__call__") as call: call.return_value = resources.Attestor() - client.create_attestor(request) # Establish that the underlying gRPC stub method was called. @@ -1107,12 +1096,12 @@ async def test_create_attestor_field_headers_async(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.CreateAttestorRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_attestor), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Attestor()) - await client.create_attestor(request) # Establish that the underlying gRPC stub method was called. @@ -1134,7 +1123,6 @@ def test_create_attestor_flattened(): with mock.patch.object(type(client.transport.create_attestor), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Attestor() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_attestor( @@ -1147,11 +1135,8 @@ def test_create_attestor_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].attestor_id == "attestor_id_value" - assert args[0].attestor == resources.Attestor(name="name_value") @@ -1195,11 +1180,8 @@ async def test_create_attestor_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].attestor_id == "attestor_id_value" - assert args[0].attestor == resources.Attestor(name="name_value") @@ -1239,21 +1221,16 @@ def test_get_attestor(transport: str = "grpc", request_type=service.GetAttestorR note_reference="note_reference_value" ), ) - response = client.get_attestor(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.GetAttestorRequest() # Establish that the response is the type that we expect. - assert isinstance(response, resources.Attestor) - assert response.name == "name_value" - assert response.description == "description_value" @@ -1273,7 +1250,6 @@ def test_get_attestor_empty_call(): client.get_attestor() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.GetAttestorRequest() @@ -1295,20 +1271,16 @@ async def test_get_attestor_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.Attestor(name="name_value", description="description_value",) ) - response = await client.get_attestor(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.GetAttestorRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.Attestor) - assert response.name == "name_value" - assert response.description == "description_value" @@ -1325,12 +1297,12 @@ def test_get_attestor_field_headers(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetAttestorRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_attestor), "__call__") as call: call.return_value = resources.Attestor() - client.get_attestor(request) # Establish that the underlying gRPC stub method was called. @@ -1352,12 +1324,12 @@ async def test_get_attestor_field_headers_async(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetAttestorRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_attestor), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Attestor()) - await client.get_attestor(request) # Establish that the underlying gRPC stub method was called. @@ -1379,7 +1351,6 @@ def test_get_attestor_flattened(): with mock.patch.object(type(client.transport.get_attestor), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Attestor() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_attestor(name="name_value",) @@ -1388,7 +1359,6 @@ def test_get_attestor_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @@ -1425,7 +1395,6 @@ async def test_get_attestor_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @@ -1464,21 +1433,16 @@ def test_update_attestor( note_reference="note_reference_value" ), ) - response = client.update_attestor(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdateAttestorRequest() # Establish that the response is the type that we expect. - assert isinstance(response, resources.Attestor) - assert response.name == "name_value" - assert response.description == "description_value" @@ -1498,7 +1462,6 @@ def test_update_attestor_empty_call(): client.update_attestor() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdateAttestorRequest() @@ -1520,20 +1483,16 @@ async def test_update_attestor_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.Attestor(name="name_value", description="description_value",) ) - response = await client.update_attestor(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdateAttestorRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.Attestor) - assert response.name == "name_value" - assert response.description == "description_value" @@ -1550,12 +1509,12 @@ def test_update_attestor_field_headers(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UpdateAttestorRequest() + request.attestor.name = "attestor.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_attestor), "__call__") as call: call.return_value = resources.Attestor() - client.update_attestor(request) # Establish that the underlying gRPC stub method was called. @@ -1579,12 +1538,12 @@ async def test_update_attestor_field_headers_async(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UpdateAttestorRequest() + request.attestor.name = "attestor.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_attestor), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Attestor()) - await client.update_attestor(request) # Establish that the underlying gRPC stub method was called. @@ -1608,7 +1567,6 @@ def test_update_attestor_flattened(): with mock.patch.object(type(client.transport.update_attestor), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Attestor() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.update_attestor(attestor=resources.Attestor(name="name_value"),) @@ -1617,7 +1575,6 @@ def test_update_attestor_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].attestor == resources.Attestor(name="name_value") @@ -1657,7 +1614,6 @@ async def test_update_attestor_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].attestor == resources.Attestor(name="name_value") @@ -1693,19 +1649,15 @@ def test_list_attestors( call.return_value = service.ListAttestorsResponse( next_page_token="next_page_token_value", ) - response = client.list_attestors(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.ListAttestorsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListAttestorsPager) - assert response.next_page_token == "next_page_token_value" @@ -1725,7 +1677,6 @@ def test_list_attestors_empty_call(): client.list_attestors() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.ListAttestorsRequest() @@ -1747,18 +1698,15 @@ async def test_list_attestors_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service.ListAttestorsResponse(next_page_token="next_page_token_value",) ) - response = await client.list_attestors(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.ListAttestorsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListAttestorsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -1775,12 +1723,12 @@ def test_list_attestors_field_headers(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ListAttestorsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_attestors), "__call__") as call: call.return_value = service.ListAttestorsResponse() - client.list_attestors(request) # Establish that the underlying gRPC stub method was called. @@ -1802,6 +1750,7 @@ async def test_list_attestors_field_headers_async(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ListAttestorsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1809,7 +1758,6 @@ async def test_list_attestors_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service.ListAttestorsResponse() ) - await client.list_attestors(request) # Establish that the underlying gRPC stub method was called. @@ -1831,7 +1779,6 @@ def test_list_attestors_flattened(): with mock.patch.object(type(client.transport.list_attestors), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = service.ListAttestorsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_attestors(parent="parent_value",) @@ -1840,7 +1787,6 @@ def test_list_attestors_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @@ -1879,7 +1825,6 @@ async def test_list_attestors_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @@ -2058,13 +2003,11 @@ def test_delete_attestor( with mock.patch.object(type(client.transport.delete_attestor), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None - response = client.delete_attestor(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.DeleteAttestorRequest() # Establish that the response is the type that we expect. @@ -2087,7 +2030,6 @@ def test_delete_attestor_empty_call(): client.delete_attestor() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.DeleteAttestorRequest() @@ -2107,13 +2049,11 @@ async def test_delete_attestor_async( with mock.patch.object(type(client.transport.delete_attestor), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_attestor(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.DeleteAttestorRequest() # Establish that the response is the type that we expect. @@ -2133,12 +2073,12 @@ def test_delete_attestor_field_headers(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.DeleteAttestorRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_attestor), "__call__") as call: call.return_value = None - client.delete_attestor(request) # Establish that the underlying gRPC stub method was called. @@ -2160,12 +2100,12 @@ async def test_delete_attestor_field_headers_async(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.DeleteAttestorRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_attestor), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_attestor(request) # Establish that the underlying gRPC stub method was called. @@ -2187,7 +2127,6 @@ def test_delete_attestor_flattened(): with mock.patch.object(type(client.transport.delete_attestor), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.delete_attestor(name="name_value",) @@ -2196,7 +2135,6 @@ def test_delete_attestor_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @@ -2233,7 +2171,6 @@ async def test_delete_attestor_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @@ -2365,10 +2302,32 @@ def test_binauthz_management_service_v1_beta1_base_transport(): getattr(transport, method)(request=object()) +@requires_google_auth_gte_1_25_0 def test_binauthz_management_service_v1_beta1_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( - auth, "load_credentials_from_file" + auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.transports.BinauthzManagementServiceV1Beta1Transport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (credentials.AnonymousCredentials(), None) + transport = transports.BinauthzManagementServiceV1Beta1Transport( + credentials_file="credentials.json", quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_binauthz_management_service_v1_beta1_base_transport_with_credentials_file_old_google_auth(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + auth, "load_credentials_from_file", autospec=True ) as load_creds, mock.patch( "google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.transports.BinauthzManagementServiceV1Beta1Transport._prep_wrapped_messages" ) as Transport: @@ -2386,7 +2345,7 @@ def test_binauthz_management_service_v1_beta1_base_transport_with_credentials_fi def test_binauthz_management_service_v1_beta1_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(auth, "default") as adc, mock.patch( + with mock.patch.object(auth, "default", autospec=True) as adc, mock.patch( "google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.transports.BinauthzManagementServiceV1Beta1Transport._prep_wrapped_messages" ) as Transport: Transport.return_value = None @@ -2395,9 +2354,23 @@ def test_binauthz_management_service_v1_beta1_base_transport_with_adc(): adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_binauthz_management_service_v1_beta1_auth_adc(): # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(auth, "default") as adc: + with mock.patch.object(auth, "default", autospec=True) as adc: + adc.return_value = (credentials.AnonymousCredentials(), None) + BinauthzManagementServiceV1Beta1Client() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_binauthz_management_service_v1_beta1_auth_adc_old_google_auth(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(auth, "default", autospec=True) as adc: adc.return_value = (credentials.AnonymousCredentials(), None) BinauthzManagementServiceV1Beta1Client() adc.assert_called_once_with( @@ -2406,20 +2379,163 @@ def test_binauthz_management_service_v1_beta1_auth_adc(): ) -def test_binauthz_management_service_v1_beta1_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [ + transports.BinauthzManagementServiceV1Beta1GrpcTransport, + transports.BinauthzManagementServiceV1Beta1GrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_binauthz_management_service_v1_beta1_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object(auth, "default") as adc: + with mock.patch.object(auth, "default", autospec=True) as adc: adc.return_value = (credentials.AnonymousCredentials(), None) - transports.BinauthzManagementServiceV1Beta1GrpcTransport( - host="squid.clam.whelk", quota_project_id="octopus" + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.BinauthzManagementServiceV1Beta1GrpcTransport, + transports.BinauthzManagementServiceV1Beta1GrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_binauthz_management_service_v1_beta1_transport_auth_adc_old_google_auth( + transport_class, +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(auth, "default", autospec=True) as adc: + adc.return_value = (credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus") adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), quota_project_id="octopus", ) +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.BinauthzManagementServiceV1Beta1GrpcTransport, grpc_helpers), + ( + transports.BinauthzManagementServiceV1Beta1GrpcAsyncIOTransport, + grpc_helpers_async, + ), + ], +) +@requires_api_core_gte_1_26_0 +def test_binauthz_management_service_v1_beta1_transport_create_channel( + transport_class, grpc_helpers +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(auth, "default", autospec=True) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "binaryauthorization.googleapis.com", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="binaryauthorization.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.BinauthzManagementServiceV1Beta1GrpcTransport, grpc_helpers), + ( + transports.BinauthzManagementServiceV1Beta1GrpcAsyncIOTransport, + grpc_helpers_async, + ), + ], +) +@requires_api_core_lt_1_26_0 +def test_binauthz_management_service_v1_beta1_transport_create_channel_old_api_core( + transport_class, grpc_helpers +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(auth, "default", autospec=True) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus") + + create_channel.assert_called_with( + "binaryauthorization.googleapis.com", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.BinauthzManagementServiceV1Beta1GrpcTransport, grpc_helpers), + ( + transports.BinauthzManagementServiceV1Beta1GrpcAsyncIOTransport, + grpc_helpers_async, + ), + ], +) +@requires_api_core_lt_1_26_0 +def test_binauthz_management_service_v1_beta1_transport_create_channel_user_scopes( + transport_class, grpc_helpers +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(auth, "default", autospec=True) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = credentials.AnonymousCredentials() + adc.return_value = (creds, None) + + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "binaryauthorization.googleapis.com", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=["1", "2"], + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize( "transport_class", [ @@ -2616,7 +2732,6 @@ def test_binauthz_management_service_v1_beta1_transport_channel_mtls_with_adc( def test_attestor_path(): project = "squid" attestor = "clam" - expected = "projects/{project}/attestors/{attestor}".format( project=project, attestor=attestor, ) @@ -2638,7 +2753,6 @@ def test_parse_attestor_path(): def test_policy_path(): project = "oyster" - expected = "projects/{project}/policy".format(project=project,) actual = BinauthzManagementServiceV1Beta1Client.policy_path(project) assert expected == actual @@ -2657,7 +2771,6 @@ def test_parse_policy_path(): def test_common_billing_account_path(): billing_account = "cuttlefish" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -2684,7 +2797,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "winkle" - expected = "folders/{folder}".format(folder=folder,) actual = BinauthzManagementServiceV1Beta1Client.common_folder_path(folder) assert expected == actual @@ -2703,7 +2815,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "scallop" - expected = "organizations/{organization}".format(organization=organization,) actual = BinauthzManagementServiceV1Beta1Client.common_organization_path( organization @@ -2724,7 +2835,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "squid" - expected = "projects/{project}".format(project=project,) actual = BinauthzManagementServiceV1Beta1Client.common_project_path(project) assert expected == actual @@ -2744,7 +2854,6 @@ def test_parse_common_project_path(): def test_common_location_path(): project = "whelk" location = "octopus" - expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) From 8f5fe5027d2c8c3d7b2ae4366ab93b3e6566e929 Mon Sep 17 00:00:00 2001 From: yoshi-automation Date: Sat, 15 May 2021 04:45:24 +0000 Subject: [PATCH 04/12] chore: upgrade gapic-generator python to 0.44.1 PiperOrigin-RevId: 370926454 Source-Author: Google APIs Source-Date: Wed Apr 28 09:58:07 2021 -0700 Source-Repo: googleapis/googleapis Source-Sha: 382ed8de075e1ddc9baa4ebf8dbc5b2c257a77b8 Source-Link: https://github.com/googleapis/googleapis/commit/382ed8de075e1ddc9baa4ebf8dbc5b2c257a77b8 --- google/cloud/binaryauthorization/__init__.py | 17 ++- .../binaryauthorization_v1beta1/__init__.py | 8 +- .../async_client.py | 21 +-- .../client.py | 21 +-- .../transports/grpc.py | 28 +--- .../transports/grpc_asyncio.py | 28 +--- .../types/resources.py | 139 +++++------------- synth.metadata | 10 +- ...st_binauthz_management_service_v1_beta1.py | 2 +- 9 files changed, 84 insertions(+), 190 deletions(-) diff --git a/google/cloud/binaryauthorization/__init__.py b/google/cloud/binaryauthorization/__init__.py index 970cae4..80ed968 100644 --- a/google/cloud/binaryauthorization/__init__.py +++ b/google/cloud/binaryauthorization/__init__.py @@ -14,12 +14,13 @@ # limitations under the License. # -from google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.async_client import ( - BinauthzManagementServiceV1Beta1AsyncClient, -) from google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.client import ( BinauthzManagementServiceV1Beta1Client, ) +from google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.async_client import ( + BinauthzManagementServiceV1Beta1AsyncClient, +) + from google.cloud.binaryauthorization_v1beta1.types.resources import AdmissionRule from google.cloud.binaryauthorization_v1beta1.types.resources import ( AdmissionWhitelistPattern, @@ -41,21 +42,21 @@ from google.cloud.binaryauthorization_v1beta1.types.service import UpdatePolicyRequest __all__ = ( + "BinauthzManagementServiceV1Beta1Client", + "BinauthzManagementServiceV1Beta1AsyncClient", "AdmissionRule", "AdmissionWhitelistPattern", "Attestor", "AttestorPublicKey", - "BinauthzManagementServiceV1Beta1AsyncClient", - "BinauthzManagementServiceV1Beta1Client", + "PkixPublicKey", + "Policy", + "UserOwnedDrydockNote", "CreateAttestorRequest", "DeleteAttestorRequest", "GetAttestorRequest", "GetPolicyRequest", "ListAttestorsRequest", "ListAttestorsResponse", - "PkixPublicKey", - "Policy", "UpdateAttestorRequest", "UpdatePolicyRequest", - "UserOwnedDrydockNote", ) diff --git a/google/cloud/binaryauthorization_v1beta1/__init__.py b/google/cloud/binaryauthorization_v1beta1/__init__.py index e66cf90..5cc2fd8 100644 --- a/google/cloud/binaryauthorization_v1beta1/__init__.py +++ b/google/cloud/binaryauthorization_v1beta1/__init__.py @@ -35,20 +35,20 @@ from .types.service import UpdatePolicyRequest __all__ = ( + "BinauthzManagementServiceV1Beta1Client", "AdmissionRule", "AdmissionWhitelistPattern", "Attestor", "AttestorPublicKey", + "PkixPublicKey", + "Policy", + "UserOwnedDrydockNote", "CreateAttestorRequest", "DeleteAttestorRequest", "GetAttestorRequest", "GetPolicyRequest", "ListAttestorsRequest", "ListAttestorsResponse", - "PkixPublicKey", - "Policy", "UpdateAttestorRequest", "UpdatePolicyRequest", - "UserOwnedDrydockNote", - "BinauthzManagementServiceV1Beta1Client", ) diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py index 89229e8..1c7b305 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py @@ -216,8 +216,7 @@ async def get_policy( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.GetPolicyRequest`): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.GetPolicy][]. name (:class:`str`): Required. The resource name of the @@ -305,8 +304,7 @@ async def update_policy( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.UpdatePolicyRequest`): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.UpdatePolicy][]. policy_ (:class:`google.cloud.binaryauthorization_v1beta1.types.Policy`): Required. A new or updated @@ -402,8 +400,7 @@ async def create_attestor( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.CreateAttestorRequest`): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.CreateAttestor][]. parent (:class:`str`): Required. The parent of this @@ -502,8 +499,7 @@ async def get_attestor( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.GetAttestorRequest`): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.GetAttestor][]. name (:class:`str`): Required. The name of the @@ -589,8 +585,7 @@ async def update_attestor( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.UpdateAttestorRequest`): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.UpdateAttestor][]. attestor (:class:`google.cloud.binaryauthorization_v1beta1.types.Attestor`): Required. The updated @@ -679,8 +674,7 @@ async def list_attestors( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.ListAttestorsRequest`): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.ListAttestors][]. parent (:class:`str`): Required. The resource name of the project associated @@ -775,8 +769,7 @@ async def delete_attestor( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.DeleteAttestorRequest`): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.DeleteAttestor][]. name (:class:`str`): Required. The name of the diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py index e836d8c..8155767 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py @@ -395,8 +395,7 @@ def get_policy( Args: request (google.cloud.binaryauthorization_v1beta1.types.GetPolicyRequest): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.GetPolicy][]. name (str): Required. The resource name of the @@ -475,8 +474,7 @@ def update_policy( Args: request (google.cloud.binaryauthorization_v1beta1.types.UpdatePolicyRequest): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.UpdatePolicy][]. policy_ (google.cloud.binaryauthorization_v1beta1.types.Policy): Required. A new or updated @@ -563,8 +561,7 @@ def create_attestor( Args: request (google.cloud.binaryauthorization_v1beta1.types.CreateAttestorRequest): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.CreateAttestor][]. parent (str): Required. The parent of this @@ -663,8 +660,7 @@ def get_attestor( Args: request (google.cloud.binaryauthorization_v1beta1.types.GetAttestorRequest): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.GetAttestor][]. name (str): Required. The name of the @@ -741,8 +737,7 @@ def update_attestor( Args: request (google.cloud.binaryauthorization_v1beta1.types.UpdateAttestorRequest): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.UpdateAttestor][]. attestor (google.cloud.binaryauthorization_v1beta1.types.Attestor): Required. The updated @@ -822,8 +817,7 @@ def list_attestors( Args: request (google.cloud.binaryauthorization_v1beta1.types.ListAttestorsRequest): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.ListAttestors][]. parent (str): Required. The resource name of the project associated @@ -909,8 +903,7 @@ def delete_attestor( Args: request (google.cloud.binaryauthorization_v1beta1.types.DeleteAttestorRequest): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.DeleteAttestor][]. name (str): Required. The name of the diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py index f6095cf..fecb21e 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py @@ -233,9 +233,7 @@ def grpc_channel(self) -> grpc.Channel: @property def get_policy(self) -> Callable[[service.GetPolicyRequest], resources.Policy]: - r"""Return a callable for the - get policy - method over gRPC. + r"""Return a callable for the get policy method over gRPC. A [policy][google.cloud.binaryauthorization.v1beta1.Policy] specifies the @@ -273,9 +271,7 @@ def get_policy(self) -> Callable[[service.GetPolicyRequest], resources.Policy]: def update_policy( self, ) -> Callable[[service.UpdatePolicyRequest], resources.Policy]: - r"""Return a callable for the - update policy - method over gRPC. + r"""Return a callable for the update policy method over gRPC. Creates or updates a project's [policy][google.cloud.binaryauthorization.v1beta1.Policy], and @@ -308,9 +304,7 @@ def update_policy( def create_attestor( self, ) -> Callable[[service.CreateAttestorRequest], resources.Attestor]: - r"""Return a callable for the - create attestor - method over gRPC. + r"""Return a callable for the create attestor method over gRPC. Creates an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor], @@ -344,9 +338,7 @@ def create_attestor( def get_attestor( self, ) -> Callable[[service.GetAttestorRequest], resources.Attestor]: - r"""Return a callable for the - get attestor - method over gRPC. + r"""Return a callable for the get attestor method over gRPC. Gets an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor]. @@ -376,9 +368,7 @@ def get_attestor( def update_attestor( self, ) -> Callable[[service.UpdateAttestorRequest], resources.Attestor]: - r"""Return a callable for the - update attestor - method over gRPC. + r"""Return a callable for the update attestor method over gRPC. Updates an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor]. @@ -408,9 +398,7 @@ def update_attestor( def list_attestors( self, ) -> Callable[[service.ListAttestorsRequest], service.ListAttestorsResponse]: - r"""Return a callable for the - list attestors - method over gRPC. + r"""Return a callable for the list attestors method over gRPC. Lists [attestors][google.cloud.binaryauthorization.v1beta1.Attestor]. @@ -436,9 +424,7 @@ def list_attestors( @property def delete_attestor(self) -> Callable[[service.DeleteAttestorRequest], empty.Empty]: - r"""Return a callable for the - delete attestor - method over gRPC. + r"""Return a callable for the delete attestor method over gRPC. Deletes an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor]. diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py index 3f7135e..edf28c8 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py @@ -239,9 +239,7 @@ def grpc_channel(self) -> aio.Channel: def get_policy( self, ) -> Callable[[service.GetPolicyRequest], Awaitable[resources.Policy]]: - r"""Return a callable for the - get policy - method over gRPC. + r"""Return a callable for the get policy method over gRPC. A [policy][google.cloud.binaryauthorization.v1beta1.Policy] specifies the @@ -279,9 +277,7 @@ def get_policy( def update_policy( self, ) -> Callable[[service.UpdatePolicyRequest], Awaitable[resources.Policy]]: - r"""Return a callable for the - update policy - method over gRPC. + r"""Return a callable for the update policy method over gRPC. Creates or updates a project's [policy][google.cloud.binaryauthorization.v1beta1.Policy], and @@ -314,9 +310,7 @@ def update_policy( def create_attestor( self, ) -> Callable[[service.CreateAttestorRequest], Awaitable[resources.Attestor]]: - r"""Return a callable for the - create attestor - method over gRPC. + r"""Return a callable for the create attestor method over gRPC. Creates an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor], @@ -350,9 +344,7 @@ def create_attestor( def get_attestor( self, ) -> Callable[[service.GetAttestorRequest], Awaitable[resources.Attestor]]: - r"""Return a callable for the - get attestor - method over gRPC. + r"""Return a callable for the get attestor method over gRPC. Gets an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor]. @@ -382,9 +374,7 @@ def get_attestor( def update_attestor( self, ) -> Callable[[service.UpdateAttestorRequest], Awaitable[resources.Attestor]]: - r"""Return a callable for the - update attestor - method over gRPC. + r"""Return a callable for the update attestor method over gRPC. Updates an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor]. @@ -416,9 +406,7 @@ def list_attestors( ) -> Callable[ [service.ListAttestorsRequest], Awaitable[service.ListAttestorsResponse] ]: - r"""Return a callable for the - list attestors - method over gRPC. + r"""Return a callable for the list attestors method over gRPC. Lists [attestors][google.cloud.binaryauthorization.v1beta1.Attestor]. @@ -446,9 +434,7 @@ def list_attestors( def delete_attestor( self, ) -> Callable[[service.DeleteAttestorRequest], Awaitable[empty.Empty]]: - r"""Return a callable for the - delete attestor - method over gRPC. + r"""Return a callable for the delete attestor method over gRPC. Deletes an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor]. diff --git a/google/cloud/binaryauthorization_v1beta1/types/resources.py b/google/cloud/binaryauthorization_v1beta1/types/resources.py index f2fb4fd..9c23801 100644 --- a/google/cloud/binaryauthorization_v1beta1/types/resources.py +++ b/google/cloud/binaryauthorization_v1beta1/types/resources.py @@ -19,15 +19,15 @@ __protobuf__ = proto.module( - package='google.cloud.binaryauthorization.v1beta1', + package="google.cloud.binaryauthorization.v1beta1", manifest={ - 'Policy', - 'AdmissionWhitelistPattern', - 'AdmissionRule', - 'Attestor', - 'UserOwnedDrydockNote', - 'PkixPublicKey', - 'AttestorPublicKey', + "Policy", + "AdmissionWhitelistPattern", + "AdmissionRule", + "Attestor", + "UserOwnedDrydockNote", + "PkixPublicKey", + "AttestorPublicKey", }, ) @@ -73,46 +73,28 @@ class Policy(proto.Message): Output only. Time when the policy was last updated. """ + class GlobalPolicyEvaluationMode(proto.Enum): r"""""" GLOBAL_POLICY_EVALUATION_MODE_UNSPECIFIED = 0 ENABLE = 1 DISABLE = 2 - name = proto.Field( - proto.STRING, - number=1, - ) - description = proto.Field( - proto.STRING, - number=6, - ) + name = proto.Field(proto.STRING, number=1,) + description = proto.Field(proto.STRING, number=6,) global_policy_evaluation_mode = proto.Field( - proto.ENUM, - number=7, - enum=GlobalPolicyEvaluationMode, + proto.ENUM, number=7, enum=GlobalPolicyEvaluationMode, ) admission_whitelist_patterns = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='AdmissionWhitelistPattern', + proto.MESSAGE, number=2, message="AdmissionWhitelistPattern", ) cluster_admission_rules = proto.MapField( - proto.STRING, - proto.MESSAGE, - number=3 - message='AdmissionRule', + proto.STRING, proto.MESSAGE, number=3, message="AdmissionRule", ) default_admission_rule = proto.Field( - proto.MESSAGE, - number=4, - message='AdmissionRule', - ) - update_time = proto.Field( - proto.MESSAGE, - number=5, - message=timestamp.Timestamp, + proto.MESSAGE, number=4, message="AdmissionRule", ) + update_time = proto.Field(proto.MESSAGE, number=5, message=timestamp.Timestamp,) class AdmissionWhitelistPattern(proto.Message): @@ -129,10 +111,7 @@ class AdmissionWhitelistPattern(proto.Message): ``registry/`` part. """ - name_pattern = proto.Field( - proto.STRING, - number=1, - ) + name_pattern = proto.Field(proto.STRING, number=1,) class AdmissionRule(proto.Message): @@ -168,6 +147,7 @@ class AdmissionRule(proto.Message): Required. The action when a pod creation is denied by the admission rule. """ + class EvaluationMode(proto.Enum): r"""""" EVALUATION_MODE_UNSPECIFIED = 0 @@ -183,20 +163,9 @@ class EnforcementMode(proto.Enum): ENFORCED_BLOCK_AND_AUDIT_LOG = 1 DRYRUN_AUDIT_LOG_ONLY = 2 - evaluation_mode = proto.Field( - proto.ENUM, - number=1, - enum=EvaluationMode, - ) - require_attestations_by = proto.RepeatedField( - proto.STRING, - number=2, - ) - enforcement_mode = proto.Field( - proto.ENUM, - number=3, - enum=EnforcementMode, - ) + evaluation_mode = proto.Field(proto.ENUM, number=1, enum=EvaluationMode,) + require_attestations_by = proto.RepeatedField(proto.STRING, number=2,) + enforcement_mode = proto.Field(proto.ENUM, number=3, enum=EnforcementMode,) class Attestor(proto.Message): @@ -219,25 +188,12 @@ class Attestor(proto.Message): updated. """ - name = proto.Field( - proto.STRING, - number=1, - ) - description = proto.Field( - proto.STRING, - number=6, - ) + name = proto.Field(proto.STRING, number=1,) + description = proto.Field(proto.STRING, number=6,) user_owned_drydock_note = proto.Field( - proto.MESSAGE, - number=3, - oneof='attestor_type', - message='UserOwnedDrydockNote', - ) - update_time = proto.Field( - proto.MESSAGE, - number=4, - message=timestamp.Timestamp, + proto.MESSAGE, number=3, oneof="attestor_type", message="UserOwnedDrydockNote", ) + update_time = proto.Field(proto.MESSAGE, number=4, message=timestamp.Timestamp,) class UserOwnedDrydockNote(proto.Message): @@ -281,19 +237,11 @@ class UserOwnedDrydockNote(proto.Message): email based on a different naming pattern. """ - note_reference = proto.Field( - proto.STRING, - number=1, - ) + note_reference = proto.Field(proto.STRING, number=1,) public_keys = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='AttestorPublicKey', - ) - delegation_service_account_email = proto.Field( - proto.STRING, - number=3, + proto.MESSAGE, number=2, message="AttestorPublicKey", ) + delegation_service_account_email = proto.Field(proto.STRING, number=3,) class PkixPublicKey(proto.Message): @@ -313,6 +261,7 @@ class PkixPublicKey(proto.Message): ``public_key_pem`` (i.e. this algorithm must match that of the public key). """ + class SignatureAlgorithm(proto.Enum): r"""Represents a signature algorithm and other information necessary to verify signatures with a given public key. This is @@ -335,15 +284,8 @@ class SignatureAlgorithm(proto.Enum): ECDSA_P384_SHA384 = 10 ECDSA_P521_SHA512 = 11 - public_key_pem = proto.Field( - proto.STRING, - number=1, - ) - signature_algorithm = proto.Field( - proto.ENUM, - number=2, - enum=SignatureAlgorithm, - ) + public_key_pem = proto.Field(proto.STRING, number=1,) + signature_algorithm = proto.Field(proto.ENUM, number=2, enum=SignatureAlgorithm,) class AttestorPublicKey(proto.Message): @@ -382,24 +324,13 @@ class AttestorPublicKey(proto.Message): public key. """ - comment = proto.Field( - proto.STRING, - number=1, - ) - id = proto.Field( - proto.STRING, - number=2, - ) + comment = proto.Field(proto.STRING, number=1,) + id = proto.Field(proto.STRING, number=2,) ascii_armored_pgp_public_key = proto.Field( - proto.STRING, - number=3, - oneof='public_key', + proto.STRING, number=3, oneof="public_key", ) pkix_public_key = proto.Field( - proto.MESSAGE, - number=5, - oneof='public_key', - message='PkixPublicKey', + proto.MESSAGE, number=5, oneof="public_key", message="PkixPublicKey", ) diff --git a/synth.metadata b/synth.metadata index 050d164..1e37e2e 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,15 +4,15 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/python-binary-authorization.git", - "sha": "82b3583c8dbc897dbb192ffc2051de5169d934c2" + "sha": "996f5010afd4372d625a9accc57647bac46770a8" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "56fc6d43fed71188d7e18f3ca003544646c4ab35", - "internalRef": "366346972" + "sha": "382ed8de075e1ddc9baa4ebf8dbc5b2c257a77b8", + "internalRef": "370926454" } } ], @@ -94,6 +94,7 @@ "google/cloud/binaryauthorization/__init__.py", "google/cloud/binaryauthorization/py.typed", "google/cloud/binaryauthorization_v1beta1/__init__.py", + "google/cloud/binaryauthorization_v1beta1/gapic_metadata.json", "google/cloud/binaryauthorization_v1beta1/py.typed", "google/cloud/binaryauthorization_v1beta1/services/__init__.py", "google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/__init__.py", @@ -120,6 +121,9 @@ "scripts/readme-gen/templates/install_portaudio.tmpl.rst", "setup.cfg", "testing/.gitignore", + "tests/__init__.py", + "tests/unit/__init__.py", + "tests/unit/gapic/__init__.py", "tests/unit/gapic/binaryauthorization_v1beta1/__init__.py", "tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py" ] diff --git a/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py b/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py index 4ccb375..5285652 100644 --- a/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py +++ b/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py @@ -2446,7 +2446,7 @@ def test_binauthz_management_service_v1_beta1_transport_create_channel( transport_class(quota_project_id="octopus", scopes=["1", "2"]) create_channel.assert_called_with( - "binaryauthorization.googleapis.com", + "binaryauthorization.googleapis.com:443", credentials=creds, credentials_file=None, quota_project_id="octopus", From 81022ef840538a461b939febf57dccd53af67724 Mon Sep 17 00:00:00 2001 From: yoshi-automation Date: Sat, 15 May 2021 04:47:06 +0000 Subject: [PATCH 05/12] chore: upgrade gapic-generator python to 0.44.1 PiperOrigin-RevId: 370989216 Source-Author: Google APIs Source-Date: Wed Apr 28 14:42:12 2021 -0700 Source-Repo: googleapis/googleapis Source-Sha: 4e825559e5ab242c4d1aafca19c83c4d1bac743e Source-Link: https://github.com/googleapis/googleapis/commit/4e825559e5ab242c4d1aafca19c83c4d1bac743e --- google/cloud/binaryauthorization/__init__.py | 17 +-- .../binaryauthorization_v1beta1/__init__.py | 8 +- .../async_client.py | 21 ++- .../client.py | 21 ++- .../transports/grpc.py | 28 +++- .../transports/grpc_asyncio.py | 28 +++- .../types/resources.py | 139 +++++++++++++----- synth.metadata | 10 +- ...st_binauthz_management_service_v1_beta1.py | 2 +- 9 files changed, 190 insertions(+), 84 deletions(-) diff --git a/google/cloud/binaryauthorization/__init__.py b/google/cloud/binaryauthorization/__init__.py index 80ed968..970cae4 100644 --- a/google/cloud/binaryauthorization/__init__.py +++ b/google/cloud/binaryauthorization/__init__.py @@ -14,13 +14,12 @@ # limitations under the License. # -from google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.client import ( - BinauthzManagementServiceV1Beta1Client, -) from google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.async_client import ( BinauthzManagementServiceV1Beta1AsyncClient, ) - +from google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.client import ( + BinauthzManagementServiceV1Beta1Client, +) from google.cloud.binaryauthorization_v1beta1.types.resources import AdmissionRule from google.cloud.binaryauthorization_v1beta1.types.resources import ( AdmissionWhitelistPattern, @@ -42,21 +41,21 @@ from google.cloud.binaryauthorization_v1beta1.types.service import UpdatePolicyRequest __all__ = ( - "BinauthzManagementServiceV1Beta1Client", - "BinauthzManagementServiceV1Beta1AsyncClient", "AdmissionRule", "AdmissionWhitelistPattern", "Attestor", "AttestorPublicKey", - "PkixPublicKey", - "Policy", - "UserOwnedDrydockNote", + "BinauthzManagementServiceV1Beta1AsyncClient", + "BinauthzManagementServiceV1Beta1Client", "CreateAttestorRequest", "DeleteAttestorRequest", "GetAttestorRequest", "GetPolicyRequest", "ListAttestorsRequest", "ListAttestorsResponse", + "PkixPublicKey", + "Policy", "UpdateAttestorRequest", "UpdatePolicyRequest", + "UserOwnedDrydockNote", ) diff --git a/google/cloud/binaryauthorization_v1beta1/__init__.py b/google/cloud/binaryauthorization_v1beta1/__init__.py index 5cc2fd8..e66cf90 100644 --- a/google/cloud/binaryauthorization_v1beta1/__init__.py +++ b/google/cloud/binaryauthorization_v1beta1/__init__.py @@ -35,20 +35,20 @@ from .types.service import UpdatePolicyRequest __all__ = ( - "BinauthzManagementServiceV1Beta1Client", "AdmissionRule", "AdmissionWhitelistPattern", "Attestor", "AttestorPublicKey", - "PkixPublicKey", - "Policy", - "UserOwnedDrydockNote", "CreateAttestorRequest", "DeleteAttestorRequest", "GetAttestorRequest", "GetPolicyRequest", "ListAttestorsRequest", "ListAttestorsResponse", + "PkixPublicKey", + "Policy", "UpdateAttestorRequest", "UpdatePolicyRequest", + "UserOwnedDrydockNote", + "BinauthzManagementServiceV1Beta1Client", ) diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py index 1c7b305..89229e8 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py @@ -216,7 +216,8 @@ async def get_policy( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.GetPolicyRequest`): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.GetPolicy][]. name (:class:`str`): Required. The resource name of the @@ -304,7 +305,8 @@ async def update_policy( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.UpdatePolicyRequest`): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.UpdatePolicy][]. policy_ (:class:`google.cloud.binaryauthorization_v1beta1.types.Policy`): Required. A new or updated @@ -400,7 +402,8 @@ async def create_attestor( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.CreateAttestorRequest`): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.CreateAttestor][]. parent (:class:`str`): Required. The parent of this @@ -499,7 +502,8 @@ async def get_attestor( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.GetAttestorRequest`): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.GetAttestor][]. name (:class:`str`): Required. The name of the @@ -585,7 +589,8 @@ async def update_attestor( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.UpdateAttestorRequest`): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.UpdateAttestor][]. attestor (:class:`google.cloud.binaryauthorization_v1beta1.types.Attestor`): Required. The updated @@ -674,7 +679,8 @@ async def list_attestors( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.ListAttestorsRequest`): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.ListAttestors][]. parent (:class:`str`): Required. The resource name of the project associated @@ -769,7 +775,8 @@ async def delete_attestor( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.DeleteAttestorRequest`): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.DeleteAttestor][]. name (:class:`str`): Required. The name of the diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py index 8155767..e836d8c 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py @@ -395,7 +395,8 @@ def get_policy( Args: request (google.cloud.binaryauthorization_v1beta1.types.GetPolicyRequest): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.GetPolicy][]. name (str): Required. The resource name of the @@ -474,7 +475,8 @@ def update_policy( Args: request (google.cloud.binaryauthorization_v1beta1.types.UpdatePolicyRequest): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.UpdatePolicy][]. policy_ (google.cloud.binaryauthorization_v1beta1.types.Policy): Required. A new or updated @@ -561,7 +563,8 @@ def create_attestor( Args: request (google.cloud.binaryauthorization_v1beta1.types.CreateAttestorRequest): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.CreateAttestor][]. parent (str): Required. The parent of this @@ -660,7 +663,8 @@ def get_attestor( Args: request (google.cloud.binaryauthorization_v1beta1.types.GetAttestorRequest): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.GetAttestor][]. name (str): Required. The name of the @@ -737,7 +741,8 @@ def update_attestor( Args: request (google.cloud.binaryauthorization_v1beta1.types.UpdateAttestorRequest): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.UpdateAttestor][]. attestor (google.cloud.binaryauthorization_v1beta1.types.Attestor): Required. The updated @@ -817,7 +822,8 @@ def list_attestors( Args: request (google.cloud.binaryauthorization_v1beta1.types.ListAttestorsRequest): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.ListAttestors][]. parent (str): Required. The resource name of the project associated @@ -903,7 +909,8 @@ def delete_attestor( Args: request (google.cloud.binaryauthorization_v1beta1.types.DeleteAttestorRequest): - The request object. Request message for + The request object. + Request message for [BinauthzManagementService.DeleteAttestor][]. name (str): Required. The name of the diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py index fecb21e..f6095cf 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py @@ -233,7 +233,9 @@ def grpc_channel(self) -> grpc.Channel: @property def get_policy(self) -> Callable[[service.GetPolicyRequest], resources.Policy]: - r"""Return a callable for the get policy method over gRPC. + r"""Return a callable for the + get policy + method over gRPC. A [policy][google.cloud.binaryauthorization.v1beta1.Policy] specifies the @@ -271,7 +273,9 @@ def get_policy(self) -> Callable[[service.GetPolicyRequest], resources.Policy]: def update_policy( self, ) -> Callable[[service.UpdatePolicyRequest], resources.Policy]: - r"""Return a callable for the update policy method over gRPC. + r"""Return a callable for the + update policy + method over gRPC. Creates or updates a project's [policy][google.cloud.binaryauthorization.v1beta1.Policy], and @@ -304,7 +308,9 @@ def update_policy( def create_attestor( self, ) -> Callable[[service.CreateAttestorRequest], resources.Attestor]: - r"""Return a callable for the create attestor method over gRPC. + r"""Return a callable for the + create attestor + method over gRPC. Creates an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor], @@ -338,7 +344,9 @@ def create_attestor( def get_attestor( self, ) -> Callable[[service.GetAttestorRequest], resources.Attestor]: - r"""Return a callable for the get attestor method over gRPC. + r"""Return a callable for the + get attestor + method over gRPC. Gets an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor]. @@ -368,7 +376,9 @@ def get_attestor( def update_attestor( self, ) -> Callable[[service.UpdateAttestorRequest], resources.Attestor]: - r"""Return a callable for the update attestor method over gRPC. + r"""Return a callable for the + update attestor + method over gRPC. Updates an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor]. @@ -398,7 +408,9 @@ def update_attestor( def list_attestors( self, ) -> Callable[[service.ListAttestorsRequest], service.ListAttestorsResponse]: - r"""Return a callable for the list attestors method over gRPC. + r"""Return a callable for the + list attestors + method over gRPC. Lists [attestors][google.cloud.binaryauthorization.v1beta1.Attestor]. @@ -424,7 +436,9 @@ def list_attestors( @property def delete_attestor(self) -> Callable[[service.DeleteAttestorRequest], empty.Empty]: - r"""Return a callable for the delete attestor method over gRPC. + r"""Return a callable for the + delete attestor + method over gRPC. Deletes an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor]. diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py index edf28c8..3f7135e 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py @@ -239,7 +239,9 @@ def grpc_channel(self) -> aio.Channel: def get_policy( self, ) -> Callable[[service.GetPolicyRequest], Awaitable[resources.Policy]]: - r"""Return a callable for the get policy method over gRPC. + r"""Return a callable for the + get policy + method over gRPC. A [policy][google.cloud.binaryauthorization.v1beta1.Policy] specifies the @@ -277,7 +279,9 @@ def get_policy( def update_policy( self, ) -> Callable[[service.UpdatePolicyRequest], Awaitable[resources.Policy]]: - r"""Return a callable for the update policy method over gRPC. + r"""Return a callable for the + update policy + method over gRPC. Creates or updates a project's [policy][google.cloud.binaryauthorization.v1beta1.Policy], and @@ -310,7 +314,9 @@ def update_policy( def create_attestor( self, ) -> Callable[[service.CreateAttestorRequest], Awaitable[resources.Attestor]]: - r"""Return a callable for the create attestor method over gRPC. + r"""Return a callable for the + create attestor + method over gRPC. Creates an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor], @@ -344,7 +350,9 @@ def create_attestor( def get_attestor( self, ) -> Callable[[service.GetAttestorRequest], Awaitable[resources.Attestor]]: - r"""Return a callable for the get attestor method over gRPC. + r"""Return a callable for the + get attestor + method over gRPC. Gets an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor]. @@ -374,7 +382,9 @@ def get_attestor( def update_attestor( self, ) -> Callable[[service.UpdateAttestorRequest], Awaitable[resources.Attestor]]: - r"""Return a callable for the update attestor method over gRPC. + r"""Return a callable for the + update attestor + method over gRPC. Updates an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor]. @@ -406,7 +416,9 @@ def list_attestors( ) -> Callable[ [service.ListAttestorsRequest], Awaitable[service.ListAttestorsResponse] ]: - r"""Return a callable for the list attestors method over gRPC. + r"""Return a callable for the + list attestors + method over gRPC. Lists [attestors][google.cloud.binaryauthorization.v1beta1.Attestor]. @@ -434,7 +446,9 @@ def list_attestors( def delete_attestor( self, ) -> Callable[[service.DeleteAttestorRequest], Awaitable[empty.Empty]]: - r"""Return a callable for the delete attestor method over gRPC. + r"""Return a callable for the + delete attestor + method over gRPC. Deletes an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor]. diff --git a/google/cloud/binaryauthorization_v1beta1/types/resources.py b/google/cloud/binaryauthorization_v1beta1/types/resources.py index 9c23801..f2fb4fd 100644 --- a/google/cloud/binaryauthorization_v1beta1/types/resources.py +++ b/google/cloud/binaryauthorization_v1beta1/types/resources.py @@ -19,15 +19,15 @@ __protobuf__ = proto.module( - package="google.cloud.binaryauthorization.v1beta1", + package='google.cloud.binaryauthorization.v1beta1', manifest={ - "Policy", - "AdmissionWhitelistPattern", - "AdmissionRule", - "Attestor", - "UserOwnedDrydockNote", - "PkixPublicKey", - "AttestorPublicKey", + 'Policy', + 'AdmissionWhitelistPattern', + 'AdmissionRule', + 'Attestor', + 'UserOwnedDrydockNote', + 'PkixPublicKey', + 'AttestorPublicKey', }, ) @@ -73,28 +73,46 @@ class Policy(proto.Message): Output only. Time when the policy was last updated. """ - class GlobalPolicyEvaluationMode(proto.Enum): r"""""" GLOBAL_POLICY_EVALUATION_MODE_UNSPECIFIED = 0 ENABLE = 1 DISABLE = 2 - name = proto.Field(proto.STRING, number=1,) - description = proto.Field(proto.STRING, number=6,) + name = proto.Field( + proto.STRING, + number=1, + ) + description = proto.Field( + proto.STRING, + number=6, + ) global_policy_evaluation_mode = proto.Field( - proto.ENUM, number=7, enum=GlobalPolicyEvaluationMode, + proto.ENUM, + number=7, + enum=GlobalPolicyEvaluationMode, ) admission_whitelist_patterns = proto.RepeatedField( - proto.MESSAGE, number=2, message="AdmissionWhitelistPattern", + proto.MESSAGE, + number=2, + message='AdmissionWhitelistPattern', ) cluster_admission_rules = proto.MapField( - proto.STRING, proto.MESSAGE, number=3, message="AdmissionRule", + proto.STRING, + proto.MESSAGE, + number=3 + message='AdmissionRule', ) default_admission_rule = proto.Field( - proto.MESSAGE, number=4, message="AdmissionRule", + proto.MESSAGE, + number=4, + message='AdmissionRule', + ) + update_time = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp.Timestamp, ) - update_time = proto.Field(proto.MESSAGE, number=5, message=timestamp.Timestamp,) class AdmissionWhitelistPattern(proto.Message): @@ -111,7 +129,10 @@ class AdmissionWhitelistPattern(proto.Message): ``registry/`` part. """ - name_pattern = proto.Field(proto.STRING, number=1,) + name_pattern = proto.Field( + proto.STRING, + number=1, + ) class AdmissionRule(proto.Message): @@ -147,7 +168,6 @@ class AdmissionRule(proto.Message): Required. The action when a pod creation is denied by the admission rule. """ - class EvaluationMode(proto.Enum): r"""""" EVALUATION_MODE_UNSPECIFIED = 0 @@ -163,9 +183,20 @@ class EnforcementMode(proto.Enum): ENFORCED_BLOCK_AND_AUDIT_LOG = 1 DRYRUN_AUDIT_LOG_ONLY = 2 - evaluation_mode = proto.Field(proto.ENUM, number=1, enum=EvaluationMode,) - require_attestations_by = proto.RepeatedField(proto.STRING, number=2,) - enforcement_mode = proto.Field(proto.ENUM, number=3, enum=EnforcementMode,) + evaluation_mode = proto.Field( + proto.ENUM, + number=1, + enum=EvaluationMode, + ) + require_attestations_by = proto.RepeatedField( + proto.STRING, + number=2, + ) + enforcement_mode = proto.Field( + proto.ENUM, + number=3, + enum=EnforcementMode, + ) class Attestor(proto.Message): @@ -188,12 +219,25 @@ class Attestor(proto.Message): updated. """ - name = proto.Field(proto.STRING, number=1,) - description = proto.Field(proto.STRING, number=6,) + name = proto.Field( + proto.STRING, + number=1, + ) + description = proto.Field( + proto.STRING, + number=6, + ) user_owned_drydock_note = proto.Field( - proto.MESSAGE, number=3, oneof="attestor_type", message="UserOwnedDrydockNote", + proto.MESSAGE, + number=3, + oneof='attestor_type', + message='UserOwnedDrydockNote', + ) + update_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp.Timestamp, ) - update_time = proto.Field(proto.MESSAGE, number=4, message=timestamp.Timestamp,) class UserOwnedDrydockNote(proto.Message): @@ -237,11 +281,19 @@ class UserOwnedDrydockNote(proto.Message): email based on a different naming pattern. """ - note_reference = proto.Field(proto.STRING, number=1,) + note_reference = proto.Field( + proto.STRING, + number=1, + ) public_keys = proto.RepeatedField( - proto.MESSAGE, number=2, message="AttestorPublicKey", + proto.MESSAGE, + number=2, + message='AttestorPublicKey', + ) + delegation_service_account_email = proto.Field( + proto.STRING, + number=3, ) - delegation_service_account_email = proto.Field(proto.STRING, number=3,) class PkixPublicKey(proto.Message): @@ -261,7 +313,6 @@ class PkixPublicKey(proto.Message): ``public_key_pem`` (i.e. this algorithm must match that of the public key). """ - class SignatureAlgorithm(proto.Enum): r"""Represents a signature algorithm and other information necessary to verify signatures with a given public key. This is @@ -284,8 +335,15 @@ class SignatureAlgorithm(proto.Enum): ECDSA_P384_SHA384 = 10 ECDSA_P521_SHA512 = 11 - public_key_pem = proto.Field(proto.STRING, number=1,) - signature_algorithm = proto.Field(proto.ENUM, number=2, enum=SignatureAlgorithm,) + public_key_pem = proto.Field( + proto.STRING, + number=1, + ) + signature_algorithm = proto.Field( + proto.ENUM, + number=2, + enum=SignatureAlgorithm, + ) class AttestorPublicKey(proto.Message): @@ -324,13 +382,24 @@ class AttestorPublicKey(proto.Message): public key. """ - comment = proto.Field(proto.STRING, number=1,) - id = proto.Field(proto.STRING, number=2,) + comment = proto.Field( + proto.STRING, + number=1, + ) + id = proto.Field( + proto.STRING, + number=2, + ) ascii_armored_pgp_public_key = proto.Field( - proto.STRING, number=3, oneof="public_key", + proto.STRING, + number=3, + oneof='public_key', ) pkix_public_key = proto.Field( - proto.MESSAGE, number=5, oneof="public_key", message="PkixPublicKey", + proto.MESSAGE, + number=5, + oneof='public_key', + message='PkixPublicKey', ) diff --git a/synth.metadata b/synth.metadata index 1e37e2e..050d164 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,15 +4,15 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/python-binary-authorization.git", - "sha": "996f5010afd4372d625a9accc57647bac46770a8" + "sha": "82b3583c8dbc897dbb192ffc2051de5169d934c2" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "382ed8de075e1ddc9baa4ebf8dbc5b2c257a77b8", - "internalRef": "370926454" + "sha": "56fc6d43fed71188d7e18f3ca003544646c4ab35", + "internalRef": "366346972" } } ], @@ -94,7 +94,6 @@ "google/cloud/binaryauthorization/__init__.py", "google/cloud/binaryauthorization/py.typed", "google/cloud/binaryauthorization_v1beta1/__init__.py", - "google/cloud/binaryauthorization_v1beta1/gapic_metadata.json", "google/cloud/binaryauthorization_v1beta1/py.typed", "google/cloud/binaryauthorization_v1beta1/services/__init__.py", "google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/__init__.py", @@ -121,9 +120,6 @@ "scripts/readme-gen/templates/install_portaudio.tmpl.rst", "setup.cfg", "testing/.gitignore", - "tests/__init__.py", - "tests/unit/__init__.py", - "tests/unit/gapic/__init__.py", "tests/unit/gapic/binaryauthorization_v1beta1/__init__.py", "tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py" ] diff --git a/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py b/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py index 5285652..4ccb375 100644 --- a/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py +++ b/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py @@ -2446,7 +2446,7 @@ def test_binauthz_management_service_v1_beta1_transport_create_channel( transport_class(quota_project_id="octopus", scopes=["1", "2"]) create_channel.assert_called_with( - "binaryauthorization.googleapis.com:443", + "binaryauthorization.googleapis.com", credentials=creds, credentials_file=None, quota_project_id="octopus", From 806707333e6a9ce4a6625dd5c5f93dae5008a689 Mon Sep 17 00:00:00 2001 From: yoshi-automation Date: Sat, 15 May 2021 04:48:32 +0000 Subject: [PATCH 06/12] chore: revert to gapic-generator-python 0.43.3 PiperOrigin-RevId: 371362703 Source-Author: Google APIs Source-Date: Fri Apr 30 10:44:40 2021 -0700 Source-Repo: googleapis/googleapis Source-Sha: 5a04154e7c7c0e98e0e4085f6e2c67bd5bff6ff8 Source-Link: https://github.com/googleapis/googleapis/commit/5a04154e7c7c0e98e0e4085f6e2c67bd5bff6ff8 --- .coveragerc | 1 + .../binauthz_management_service_v1_beta1.rst | 1 + docs/binaryauthorization_v1beta1/services.rst | 2 +- google/cloud/binaryauthorization/__init__.py | 1 + .../binaryauthorization_v1beta1/__init__.py | 3 +- .../gapic_metadata.json | 93 ----- .../services/__init__.py | 1 + .../__init__.py | 2 + .../async_client.py | 44 ++- .../client.py | 45 ++- .../pagers.py | 2 + .../transports/__init__.py | 2 + .../transports/base.py | 117 ++---- .../transports/grpc.py | 42 +-- .../transports/grpc_asyncio.py | 44 +-- .../types/__init__.py | 2 + .../types/resources.py | 159 +++----- .../types/service.py | 34 +- ...up_binaryauthorization_v1beta1_keywords.py | 19 +- synth.metadata | 6 +- tests/__init__.py | 15 - tests/unit/__init__.py | 15 - tests/unit/gapic/__init__.py | 15 - .../binaryauthorization_v1beta1/__init__.py | 1 + ...st_binauthz_management_service_v1_beta1.py | 353 ++++++------------ 25 files changed, 353 insertions(+), 666 deletions(-) delete mode 100644 google/cloud/binaryauthorization_v1beta1/gapic_metadata.json delete mode 100644 tests/__init__.py delete mode 100644 tests/unit/__init__.py delete mode 100644 tests/unit/gapic/__init__.py diff --git a/.coveragerc b/.coveragerc index 95c4014..5ff8242 100644 --- a/.coveragerc +++ b/.coveragerc @@ -2,6 +2,7 @@ branch = True [report] +fail_under = 100 show_missing = True omit = google/cloud/binaryauthorization/__init__.py diff --git a/docs/binaryauthorization_v1beta1/binauthz_management_service_v1_beta1.rst b/docs/binaryauthorization_v1beta1/binauthz_management_service_v1_beta1.rst index 22016d0..5868c89 100644 --- a/docs/binaryauthorization_v1beta1/binauthz_management_service_v1_beta1.rst +++ b/docs/binaryauthorization_v1beta1/binauthz_management_service_v1_beta1.rst @@ -5,6 +5,7 @@ BinauthzManagementServiceV1Beta1 :members: :inherited-members: + .. automodule:: google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.pagers :members: :inherited-members: diff --git a/docs/binaryauthorization_v1beta1/services.rst b/docs/binaryauthorization_v1beta1/services.rst index 6366869..e96610a 100644 --- a/docs/binaryauthorization_v1beta1/services.rst +++ b/docs/binaryauthorization_v1beta1/services.rst @@ -3,4 +3,4 @@ Services for Google Cloud Binaryauthorization v1beta1 API .. toctree:: :maxdepth: 2 -binauthz_management_service_v1_beta1 + binauthz_management_service_v1_beta1 diff --git a/google/cloud/binaryauthorization/__init__.py b/google/cloud/binaryauthorization/__init__.py index 970cae4..f082bea 100644 --- a/google/cloud/binaryauthorization/__init__.py +++ b/google/cloud/binaryauthorization/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/google/cloud/binaryauthorization_v1beta1/__init__.py b/google/cloud/binaryauthorization_v1beta1/__init__.py index e66cf90..5f14b9c 100644 --- a/google/cloud/binaryauthorization_v1beta1/__init__.py +++ b/google/cloud/binaryauthorization_v1beta1/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +18,6 @@ from .services.binauthz_management_service_v1_beta1 import ( BinauthzManagementServiceV1Beta1Client, ) - from .types.resources import AdmissionRule from .types.resources import AdmissionWhitelistPattern from .types.resources import Attestor @@ -34,6 +34,7 @@ from .types.service import UpdateAttestorRequest from .types.service import UpdatePolicyRequest + __all__ = ( "AdmissionRule", "AdmissionWhitelistPattern", diff --git a/google/cloud/binaryauthorization_v1beta1/gapic_metadata.json b/google/cloud/binaryauthorization_v1beta1/gapic_metadata.json deleted file mode 100644 index 8e56955..0000000 --- a/google/cloud/binaryauthorization_v1beta1/gapic_metadata.json +++ /dev/null @@ -1,93 +0,0 @@ - { - "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", - "language": "python", - "libraryPackage": "google.cloud.binaryauthorization_v1beta1", - "protoPackage": "google.cloud.binaryauthorization.v1beta1", - "schema": "1.0", - "services": { - "BinauthzManagementServiceV1Beta1": { - "clients": { - "grpc": { - "libraryClient": "BinauthzManagementServiceV1Beta1Client", - "rpcs": { - "CreateAttestor": { - "methods": [ - "create_attestor" - ] - }, - "DeleteAttestor": { - "methods": [ - "delete_attestor" - ] - }, - "GetAttestor": { - "methods": [ - "get_attestor" - ] - }, - "GetPolicy": { - "methods": [ - "get_policy" - ] - }, - "ListAttestors": { - "methods": [ - "list_attestors" - ] - }, - "UpdateAttestor": { - "methods": [ - "update_attestor" - ] - }, - "UpdatePolicy": { - "methods": [ - "update_policy" - ] - } - } - }, - "grpc-async": { - "libraryClient": "BinauthzManagementServiceV1Beta1AsyncClient", - "rpcs": { - "CreateAttestor": { - "methods": [ - "create_attestor" - ] - }, - "DeleteAttestor": { - "methods": [ - "delete_attestor" - ] - }, - "GetAttestor": { - "methods": [ - "get_attestor" - ] - }, - "GetPolicy": { - "methods": [ - "get_policy" - ] - }, - "ListAttestors": { - "methods": [ - "list_attestors" - ] - }, - "UpdateAttestor": { - "methods": [ - "update_attestor" - ] - }, - "UpdatePolicy": { - "methods": [ - "update_policy" - ] - } - } - } - } - } - } -} diff --git a/google/cloud/binaryauthorization_v1beta1/services/__init__.py b/google/cloud/binaryauthorization_v1beta1/services/__init__.py index 4de6597..42ffdf2 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/__init__.py +++ b/google/cloud/binaryauthorization_v1beta1/services/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/__init__.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/__init__.py index e133615..f832d0c 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/__init__.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # + from .client import BinauthzManagementServiceV1Beta1Client from .async_client import BinauthzManagementServiceV1Beta1AsyncClient diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py index 89229e8..c8c2474 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # + from collections import OrderedDict import functools import re @@ -32,6 +34,7 @@ from google.cloud.binaryauthorization_v1beta1.types import resources from google.cloud.binaryauthorization_v1beta1.types import service from google.protobuf import timestamp_pb2 as timestamp # type: ignore + from .transports.base import ( BinauthzManagementServiceV1Beta1Transport, DEFAULT_CLIENT_INFO, @@ -65,30 +68,35 @@ class BinauthzManagementServiceV1Beta1AsyncClient: parse_policy_path = staticmethod( BinauthzManagementServiceV1Beta1Client.parse_policy_path ) + common_billing_account_path = staticmethod( BinauthzManagementServiceV1Beta1Client.common_billing_account_path ) parse_common_billing_account_path = staticmethod( BinauthzManagementServiceV1Beta1Client.parse_common_billing_account_path ) + common_folder_path = staticmethod( BinauthzManagementServiceV1Beta1Client.common_folder_path ) parse_common_folder_path = staticmethod( BinauthzManagementServiceV1Beta1Client.parse_common_folder_path ) + common_organization_path = staticmethod( BinauthzManagementServiceV1Beta1Client.common_organization_path ) parse_common_organization_path = staticmethod( BinauthzManagementServiceV1Beta1Client.parse_common_organization_path ) + common_project_path = staticmethod( BinauthzManagementServiceV1Beta1Client.common_project_path ) parse_common_project_path = staticmethod( BinauthzManagementServiceV1Beta1Client.parse_common_project_path ) + common_location_path = staticmethod( BinauthzManagementServiceV1Beta1Client.common_location_path ) @@ -184,6 +192,7 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ + self._client = BinauthzManagementServiceV1Beta1Client( credentials=credentials, transport=transport, @@ -216,8 +225,7 @@ async def get_policy( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.GetPolicyRequest`): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.GetPolicy][]. name (:class:`str`): Required. The resource name of the @@ -227,6 +235,7 @@ async def get_policy( This corresponds to the ``name`` 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. @@ -253,6 +262,7 @@ async def get_policy( # If we have keyword arguments corresponding to fields on the # request, apply these. + if name is not None: request.name = name @@ -305,8 +315,7 @@ async def update_policy( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.UpdatePolicyRequest`): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.UpdatePolicy][]. policy_ (:class:`google.cloud.binaryauthorization_v1beta1.types.Policy`): Required. A new or updated @@ -319,6 +328,7 @@ async def update_policy( This corresponds to the ``policy_`` 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. @@ -345,6 +355,7 @@ async def update_policy( # If we have keyword arguments corresponding to fields on the # request, apply these. + if policy_ is not None: request.policy_ = policy_ @@ -402,8 +413,7 @@ async def create_attestor( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.CreateAttestorRequest`): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.CreateAttestor][]. parent (:class:`str`): Required. The parent of this @@ -431,6 +441,7 @@ async def create_attestor( This corresponds to the ``attestor`` 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. @@ -458,6 +469,7 @@ async def create_attestor( # If we have keyword arguments corresponding to fields on the # request, apply these. + if parent is not None: request.parent = parent if attestor_id is not None: @@ -502,8 +514,7 @@ async def get_attestor( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.GetAttestorRequest`): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.GetAttestor][]. name (:class:`str`): Required. The name of the @@ -513,6 +524,7 @@ async def get_attestor( This corresponds to the ``name`` 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. @@ -540,6 +552,7 @@ async def get_attestor( # If we have keyword arguments corresponding to fields on the # request, apply these. + if name is not None: request.name = name @@ -589,8 +602,7 @@ async def update_attestor( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.UpdateAttestorRequest`): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.UpdateAttestor][]. attestor (:class:`google.cloud.binaryauthorization_v1beta1.types.Attestor`): Required. The updated @@ -603,6 +615,7 @@ async def update_attestor( This corresponds to the ``attestor`` 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. @@ -630,6 +643,7 @@ async def update_attestor( # If we have keyword arguments corresponding to fields on the # request, apply these. + if attestor is not None: request.attestor = attestor @@ -679,8 +693,7 @@ async def list_attestors( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.ListAttestorsRequest`): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.ListAttestors][]. parent (:class:`str`): Required. The resource name of the project associated @@ -691,6 +704,7 @@ async def list_attestors( This corresponds to the ``parent`` 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. @@ -720,6 +734,7 @@ async def list_attestors( # If we have keyword arguments corresponding to fields on the # request, apply these. + if parent is not None: request.parent = parent @@ -775,8 +790,7 @@ async def delete_attestor( Args: request (:class:`google.cloud.binaryauthorization_v1beta1.types.DeleteAttestorRequest`): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.DeleteAttestor][]. name (:class:`str`): Required. The name of the @@ -786,6 +800,7 @@ async def delete_attestor( This corresponds to the ``name`` 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. @@ -806,6 +821,7 @@ async def delete_attestor( # If we have keyword arguments corresponding to fields on the # request, apply these. + if name is not None: request.name = name diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py index e836d8c..4dbbd25 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # + from collections import OrderedDict from distutils import util import os @@ -36,6 +38,7 @@ from google.cloud.binaryauthorization_v1beta1.types import resources from google.cloud.binaryauthorization_v1beta1.types import service from google.protobuf import timestamp_pb2 as timestamp # type: ignore + from .transports.base import ( BinauthzManagementServiceV1Beta1Transport, DEFAULT_CLIENT_INFO, @@ -395,8 +398,7 @@ def get_policy( Args: request (google.cloud.binaryauthorization_v1beta1.types.GetPolicyRequest): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.GetPolicy][]. name (str): Required. The resource name of the @@ -406,6 +408,7 @@ def get_policy( This corresponds to the ``name`` 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. @@ -434,8 +437,10 @@ def get_policy( # there are no flattened fields. if not isinstance(request, service.GetPolicyRequest): request = service.GetPolicyRequest(request) + # If we have keyword arguments corresponding to fields on the # request, apply these. + if name is not None: request.name = name @@ -475,8 +480,7 @@ def update_policy( Args: request (google.cloud.binaryauthorization_v1beta1.types.UpdatePolicyRequest): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.UpdatePolicy][]. policy_ (google.cloud.binaryauthorization_v1beta1.types.Policy): Required. A new or updated @@ -489,6 +493,7 @@ def update_policy( This corresponds to the ``policy_`` 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. @@ -517,8 +522,10 @@ def update_policy( # there are no flattened fields. if not isinstance(request, service.UpdatePolicyRequest): request = service.UpdatePolicyRequest(request) + # If we have keyword arguments corresponding to fields on the # request, apply these. + if policy_ is not None: request.policy_ = policy_ @@ -563,8 +570,7 @@ def create_attestor( Args: request (google.cloud.binaryauthorization_v1beta1.types.CreateAttestorRequest): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.CreateAttestor][]. parent (str): Required. The parent of this @@ -592,6 +598,7 @@ def create_attestor( This corresponds to the ``attestor`` 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. @@ -621,8 +628,10 @@ def create_attestor( # there are no flattened fields. if not isinstance(request, service.CreateAttestorRequest): request = service.CreateAttestorRequest(request) + # If we have keyword arguments corresponding to fields on the # request, apply these. + if parent is not None: request.parent = parent if attestor_id is not None: @@ -663,8 +672,7 @@ def get_attestor( Args: request (google.cloud.binaryauthorization_v1beta1.types.GetAttestorRequest): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.GetAttestor][]. name (str): Required. The name of the @@ -674,6 +682,7 @@ def get_attestor( This corresponds to the ``name`` 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. @@ -703,8 +712,10 @@ def get_attestor( # there are no flattened fields. if not isinstance(request, service.GetAttestorRequest): request = service.GetAttestorRequest(request) + # If we have keyword arguments corresponding to fields on the # request, apply these. + if name is not None: request.name = name @@ -741,8 +752,7 @@ def update_attestor( Args: request (google.cloud.binaryauthorization_v1beta1.types.UpdateAttestorRequest): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.UpdateAttestor][]. attestor (google.cloud.binaryauthorization_v1beta1.types.Attestor): Required. The updated @@ -755,6 +765,7 @@ def update_attestor( This corresponds to the ``attestor`` 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. @@ -784,8 +795,10 @@ def update_attestor( # there are no flattened fields. if not isinstance(request, service.UpdateAttestorRequest): request = service.UpdateAttestorRequest(request) + # If we have keyword arguments corresponding to fields on the # request, apply these. + if attestor is not None: request.attestor = attestor @@ -822,8 +835,7 @@ def list_attestors( Args: request (google.cloud.binaryauthorization_v1beta1.types.ListAttestorsRequest): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.ListAttestors][]. parent (str): Required. The resource name of the project associated @@ -834,6 +846,7 @@ def list_attestors( This corresponds to the ``parent`` 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. @@ -865,8 +878,10 @@ def list_attestors( # there are no flattened fields. if not isinstance(request, service.ListAttestorsRequest): request = service.ListAttestorsRequest(request) + # If we have keyword arguments corresponding to fields on the # request, apply these. + if parent is not None: request.parent = parent @@ -909,8 +924,7 @@ def delete_attestor( Args: request (google.cloud.binaryauthorization_v1beta1.types.DeleteAttestorRequest): - The request object. - Request message for + The request object. Request message for [BinauthzManagementService.DeleteAttestor][]. name (str): Required. The name of the @@ -920,6 +934,7 @@ def delete_attestor( This corresponds to the ``name`` 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. @@ -942,8 +957,10 @@ def delete_attestor( # there are no flattened fields. if not isinstance(request, service.DeleteAttestorRequest): request = service.DeleteAttestorRequest(request) + # If we have keyword arguments corresponding to fields on the # request, apply these. + if name is not None: request.name = name diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/pagers.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/pagers.py index 9aecf4b..42c4659 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/pagers.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/pagers.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # + from typing import ( Any, AsyncIterable, diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/__init__.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/__init__.py index bf3c24d..78aef3f 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/__init__.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # + from collections import OrderedDict from typing import Dict, Type diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/base.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/base.py index c785aa1..9bc0a22 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/base.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/base.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,13 +14,12 @@ # See the License for the specific language governing permissions and # limitations under the License. # + import abc -from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version +import typing import pkg_resources from google import auth # type: ignore -import google.api_core # type: ignore from google.api_core import exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore @@ -29,6 +29,7 @@ from google.cloud.binaryauthorization_v1beta1.types import service from google.protobuf import empty_pb2 as empty # type: ignore + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=pkg_resources.get_distribution( @@ -38,41 +39,27 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - -_API_CORE_VERSION = google.api_core.__version__ - class BinauthzManagementServiceV1Beta1Transport(abc.ABC): """Abstract transport class for BinauthzManagementServiceV1Beta1.""" AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) - DEFAULT_HOST: str = "binaryauthorization.googleapis.com" - def __init__( self, *, - host: str = DEFAULT_HOST, + host: str = "binaryauthorization.googleapis.com", credentials: credentials.Credentials = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, + credentials_file: typing.Optional[str] = None, + scopes: typing.Optional[typing.Sequence[str]] = AUTH_SCOPES, + quota_project_id: typing.Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, **kwargs, ) -> None: """Instantiate the transport. Args: - host (Optional[str]): - The hostname to connect to. + host (Optional[str]): The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -81,7 +68,7 @@ def __init__( credentials_file (Optional[str]): A file with credentials that can be loaded with :func:`google.auth.load_credentials_from_file`. This argument is mutually exclusive with credentials. - scopes (Optional[Sequence[str]]): A list of scopes. + scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -95,8 +82,6 @@ def __init__( host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) - # Save the scopes. self._scopes = scopes or self.AUTH_SCOPES @@ -109,62 +94,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, **scopes_kwargs, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - **scopes_kwargs, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # TODO(busunkim): These two class methods are in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-api-core - # and google-auth are increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - - # TODO: Remove this function once google-api-core >= 1.26.0 is required - @classmethod - def _get_self_signed_jwt_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Union[Optional[Sequence[str]], str]]: - """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" - - self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} - - if _API_CORE_VERSION and ( - packaging.version.parse(_API_CORE_VERSION) - >= packaging.version.parse("1.26.0") - ): - self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES - self_signed_jwt_kwargs["scopes"] = scopes - self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST - else: - self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES - - return self_signed_jwt_kwargs - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -260,61 +200,66 @@ def _prep_wrapped_messages(self, client_info): @property def get_policy( self, - ) -> Callable[ - [service.GetPolicyRequest], Union[resources.Policy, Awaitable[resources.Policy]] + ) -> typing.Callable[ + [service.GetPolicyRequest], + typing.Union[resources.Policy, typing.Awaitable[resources.Policy]], ]: raise NotImplementedError() @property def update_policy( self, - ) -> Callable[ + ) -> typing.Callable[ [service.UpdatePolicyRequest], - Union[resources.Policy, Awaitable[resources.Policy]], + typing.Union[resources.Policy, typing.Awaitable[resources.Policy]], ]: raise NotImplementedError() @property def create_attestor( self, - ) -> Callable[ + ) -> typing.Callable[ [service.CreateAttestorRequest], - Union[resources.Attestor, Awaitable[resources.Attestor]], + typing.Union[resources.Attestor, typing.Awaitable[resources.Attestor]], ]: raise NotImplementedError() @property def get_attestor( self, - ) -> Callable[ + ) -> typing.Callable[ [service.GetAttestorRequest], - Union[resources.Attestor, Awaitable[resources.Attestor]], + typing.Union[resources.Attestor, typing.Awaitable[resources.Attestor]], ]: raise NotImplementedError() @property def update_attestor( self, - ) -> Callable[ + ) -> typing.Callable[ [service.UpdateAttestorRequest], - Union[resources.Attestor, Awaitable[resources.Attestor]], + typing.Union[resources.Attestor, typing.Awaitable[resources.Attestor]], ]: raise NotImplementedError() @property def list_attestors( self, - ) -> Callable[ + ) -> typing.Callable[ [service.ListAttestorsRequest], - Union[service.ListAttestorsResponse, Awaitable[service.ListAttestorsResponse]], + typing.Union[ + service.ListAttestorsResponse, + typing.Awaitable[service.ListAttestorsResponse], + ], ]: raise NotImplementedError() @property def delete_attestor( self, - ) -> Callable[ - [service.DeleteAttestorRequest], Union[empty.Empty, Awaitable[empty.Empty]] + ) -> typing.Callable[ + [service.DeleteAttestorRequest], + typing.Union[empty.Empty, typing.Awaitable[empty.Empty]], ]: raise NotImplementedError() diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py index f6095cf..e2a2f5b 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,8 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # + import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple, Union +from typing import Callable, Dict, Optional, Sequence, Tuple from google.api_core import grpc_helpers # type: ignore from google.api_core import gapic_v1 # type: ignore @@ -27,6 +29,7 @@ from google.cloud.binaryauthorization_v1beta1.types import resources from google.cloud.binaryauthorization_v1beta1.types import service from google.protobuf import empty_pb2 as empty # type: ignore + from .base import BinauthzManagementServiceV1Beta1Transport, DEFAULT_CLIENT_INFO @@ -71,8 +74,7 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): - The hostname to connect to. + host (Optional[str]): The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -213,15 +215,13 @@ def create_channel( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ - - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - + scopes = scopes or cls.AUTH_SCOPES return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, + scopes=scopes, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, **kwargs, ) @@ -233,9 +233,7 @@ def grpc_channel(self) -> grpc.Channel: @property def get_policy(self) -> Callable[[service.GetPolicyRequest], resources.Policy]: - r"""Return a callable for the - get policy - method over gRPC. + r"""Return a callable for the get policy method over gRPC. A [policy][google.cloud.binaryauthorization.v1beta1.Policy] specifies the @@ -273,9 +271,7 @@ def get_policy(self) -> Callable[[service.GetPolicyRequest], resources.Policy]: def update_policy( self, ) -> Callable[[service.UpdatePolicyRequest], resources.Policy]: - r"""Return a callable for the - update policy - method over gRPC. + r"""Return a callable for the update policy method over gRPC. Creates or updates a project's [policy][google.cloud.binaryauthorization.v1beta1.Policy], and @@ -308,9 +304,7 @@ def update_policy( def create_attestor( self, ) -> Callable[[service.CreateAttestorRequest], resources.Attestor]: - r"""Return a callable for the - create attestor - method over gRPC. + r"""Return a callable for the create attestor method over gRPC. Creates an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor], @@ -344,9 +338,7 @@ def create_attestor( def get_attestor( self, ) -> Callable[[service.GetAttestorRequest], resources.Attestor]: - r"""Return a callable for the - get attestor - method over gRPC. + r"""Return a callable for the get attestor method over gRPC. Gets an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor]. @@ -376,9 +368,7 @@ def get_attestor( def update_attestor( self, ) -> Callable[[service.UpdateAttestorRequest], resources.Attestor]: - r"""Return a callable for the - update attestor - method over gRPC. + r"""Return a callable for the update attestor method over gRPC. Updates an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor]. @@ -408,9 +398,7 @@ def update_attestor( def list_attestors( self, ) -> Callable[[service.ListAttestorsRequest], service.ListAttestorsResponse]: - r"""Return a callable for the - list attestors - method over gRPC. + r"""Return a callable for the list attestors method over gRPC. Lists [attestors][google.cloud.binaryauthorization.v1beta1.Attestor]. @@ -436,9 +424,7 @@ def list_attestors( @property def delete_attestor(self) -> Callable[[service.DeleteAttestorRequest], empty.Empty]: - r"""Return a callable for the - delete attestor - method over gRPC. + r"""Return a callable for the delete attestor method over gRPC. Deletes an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor]. diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py index 3f7135e..4b621da 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,15 +14,15 @@ # See the License for the specific language governing permissions and # limitations under the License. # + import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple from google.api_core import gapic_v1 # type: ignore from google.api_core import grpc_helpers_async # type: ignore from google import auth # type: ignore from google.auth import credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -29,6 +30,7 @@ from google.cloud.binaryauthorization_v1beta1.types import resources from google.cloud.binaryauthorization_v1beta1.types import service from google.protobuf import empty_pb2 as empty # type: ignore + from .base import BinauthzManagementServiceV1Beta1Transport, DEFAULT_CLIENT_INFO from .grpc import BinauthzManagementServiceV1Beta1GrpcTransport @@ -88,15 +90,13 @@ def create_channel( Returns: aio.Channel: A gRPC AsyncIO channel object. """ - - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - + scopes = scopes or cls.AUTH_SCOPES return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, + scopes=scopes, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, **kwargs, ) @@ -118,8 +118,7 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): - The hostname to connect to. + host (Optional[str]): The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -177,6 +176,7 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None + else: if api_mtls_endpoint: host = api_mtls_endpoint @@ -239,9 +239,7 @@ def grpc_channel(self) -> aio.Channel: def get_policy( self, ) -> Callable[[service.GetPolicyRequest], Awaitable[resources.Policy]]: - r"""Return a callable for the - get policy - method over gRPC. + r"""Return a callable for the get policy method over gRPC. A [policy][google.cloud.binaryauthorization.v1beta1.Policy] specifies the @@ -279,9 +277,7 @@ def get_policy( def update_policy( self, ) -> Callable[[service.UpdatePolicyRequest], Awaitable[resources.Policy]]: - r"""Return a callable for the - update policy - method over gRPC. + r"""Return a callable for the update policy method over gRPC. Creates or updates a project's [policy][google.cloud.binaryauthorization.v1beta1.Policy], and @@ -314,9 +310,7 @@ def update_policy( def create_attestor( self, ) -> Callable[[service.CreateAttestorRequest], Awaitable[resources.Attestor]]: - r"""Return a callable for the - create attestor - method over gRPC. + r"""Return a callable for the create attestor method over gRPC. Creates an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor], @@ -350,9 +344,7 @@ def create_attestor( def get_attestor( self, ) -> Callable[[service.GetAttestorRequest], Awaitable[resources.Attestor]]: - r"""Return a callable for the - get attestor - method over gRPC. + r"""Return a callable for the get attestor method over gRPC. Gets an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor]. @@ -382,9 +374,7 @@ def get_attestor( def update_attestor( self, ) -> Callable[[service.UpdateAttestorRequest], Awaitable[resources.Attestor]]: - r"""Return a callable for the - update attestor - method over gRPC. + r"""Return a callable for the update attestor method over gRPC. Updates an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor]. @@ -416,9 +406,7 @@ def list_attestors( ) -> Callable[ [service.ListAttestorsRequest], Awaitable[service.ListAttestorsResponse] ]: - r"""Return a callable for the - list attestors - method over gRPC. + r"""Return a callable for the list attestors method over gRPC. Lists [attestors][google.cloud.binaryauthorization.v1beta1.Attestor]. @@ -446,9 +434,7 @@ def list_attestors( def delete_attestor( self, ) -> Callable[[service.DeleteAttestorRequest], Awaitable[empty.Empty]]: - r"""Return a callable for the - delete attestor - method over gRPC. + r"""Return a callable for the delete attestor method over gRPC. Deletes an [attestor][google.cloud.binaryauthorization.v1beta1.Attestor]. diff --git a/google/cloud/binaryauthorization_v1beta1/types/__init__.py b/google/cloud/binaryauthorization_v1beta1/types/__init__.py index 122112d..b4424d4 100644 --- a/google/cloud/binaryauthorization_v1beta1/types/__init__.py +++ b/google/cloud/binaryauthorization_v1beta1/types/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # + from .resources import ( AdmissionRule, AdmissionWhitelistPattern, diff --git a/google/cloud/binaryauthorization_v1beta1/types/resources.py b/google/cloud/binaryauthorization_v1beta1/types/resources.py index f2fb4fd..7866476 100644 --- a/google/cloud/binaryauthorization_v1beta1/types/resources.py +++ b/google/cloud/binaryauthorization_v1beta1/types/resources.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,21 +14,23 @@ # See the License for the specific language governing permissions and # limitations under the License. # + import proto # type: ignore + from google.protobuf import timestamp_pb2 as timestamp # type: ignore __protobuf__ = proto.module( - package='google.cloud.binaryauthorization.v1beta1', + package="google.cloud.binaryauthorization.v1beta1", manifest={ - 'Policy', - 'AdmissionWhitelistPattern', - 'AdmissionRule', - 'Attestor', - 'UserOwnedDrydockNote', - 'PkixPublicKey', - 'AttestorPublicKey', + "Policy", + "AdmissionWhitelistPattern", + "AdmissionRule", + "Attestor", + "UserOwnedDrydockNote", + "PkixPublicKey", + "AttestorPublicKey", }, ) @@ -73,47 +76,35 @@ class Policy(proto.Message): Output only. Time when the policy was last updated. """ + class GlobalPolicyEvaluationMode(proto.Enum): r"""""" GLOBAL_POLICY_EVALUATION_MODE_UNSPECIFIED = 0 ENABLE = 1 DISABLE = 2 - name = proto.Field( - proto.STRING, - number=1, - ) - description = proto.Field( - proto.STRING, - number=6, - ) + name = proto.Field(proto.STRING, number=1) + + description = proto.Field(proto.STRING, number=6) + global_policy_evaluation_mode = proto.Field( - proto.ENUM, - number=7, - enum=GlobalPolicyEvaluationMode, + proto.ENUM, number=7, enum=GlobalPolicyEvaluationMode, ) + admission_whitelist_patterns = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='AdmissionWhitelistPattern', + proto.MESSAGE, number=2, message="AdmissionWhitelistPattern", ) + cluster_admission_rules = proto.MapField( - proto.STRING, - proto.MESSAGE, - number=3 - message='AdmissionRule', + proto.STRING, proto.MESSAGE, number=3, message="AdmissionRule", ) + default_admission_rule = proto.Field( - proto.MESSAGE, - number=4, - message='AdmissionRule', - ) - update_time = proto.Field( - proto.MESSAGE, - number=5, - message=timestamp.Timestamp, + proto.MESSAGE, number=4, message="AdmissionRule", ) + update_time = proto.Field(proto.MESSAGE, number=5, message=timestamp.Timestamp,) + class AdmissionWhitelistPattern(proto.Message): r"""An [admission allowlist @@ -129,10 +120,7 @@ class AdmissionWhitelistPattern(proto.Message): ``registry/`` part. """ - name_pattern = proto.Field( - proto.STRING, - number=1, - ) + name_pattern = proto.Field(proto.STRING, number=1) class AdmissionRule(proto.Message): @@ -168,6 +156,7 @@ class AdmissionRule(proto.Message): Required. The action when a pod creation is denied by the admission rule. """ + class EvaluationMode(proto.Enum): r"""""" EVALUATION_MODE_UNSPECIFIED = 0 @@ -183,20 +172,11 @@ class EnforcementMode(proto.Enum): ENFORCED_BLOCK_AND_AUDIT_LOG = 1 DRYRUN_AUDIT_LOG_ONLY = 2 - evaluation_mode = proto.Field( - proto.ENUM, - number=1, - enum=EvaluationMode, - ) - require_attestations_by = proto.RepeatedField( - proto.STRING, - number=2, - ) - enforcement_mode = proto.Field( - proto.ENUM, - number=3, - enum=EnforcementMode, - ) + evaluation_mode = proto.Field(proto.ENUM, number=1, enum=EvaluationMode,) + + require_attestations_by = proto.RepeatedField(proto.STRING, number=2) + + enforcement_mode = proto.Field(proto.ENUM, number=3, enum=EnforcementMode,) class Attestor(proto.Message): @@ -219,26 +199,16 @@ class Attestor(proto.Message): updated. """ - name = proto.Field( - proto.STRING, - number=1, - ) - description = proto.Field( - proto.STRING, - number=6, - ) + name = proto.Field(proto.STRING, number=1) + + description = proto.Field(proto.STRING, number=6) + user_owned_drydock_note = proto.Field( - proto.MESSAGE, - number=3, - oneof='attestor_type', - message='UserOwnedDrydockNote', - ) - update_time = proto.Field( - proto.MESSAGE, - number=4, - message=timestamp.Timestamp, + proto.MESSAGE, number=3, oneof="attestor_type", message="UserOwnedDrydockNote", ) + update_time = proto.Field(proto.MESSAGE, number=4, message=timestamp.Timestamp,) + class UserOwnedDrydockNote(proto.Message): r"""An [user owned drydock @@ -281,20 +251,14 @@ class UserOwnedDrydockNote(proto.Message): email based on a different naming pattern. """ - note_reference = proto.Field( - proto.STRING, - number=1, - ) + note_reference = proto.Field(proto.STRING, number=1) + public_keys = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='AttestorPublicKey', - ) - delegation_service_account_email = proto.Field( - proto.STRING, - number=3, + proto.MESSAGE, number=2, message="AttestorPublicKey", ) + delegation_service_account_email = proto.Field(proto.STRING, number=3) + class PkixPublicKey(proto.Message): r"""A public key in the PkixPublicKey format (see @@ -313,6 +277,7 @@ class PkixPublicKey(proto.Message): ``public_key_pem`` (i.e. this algorithm must match that of the public key). """ + class SignatureAlgorithm(proto.Enum): r"""Represents a signature algorithm and other information necessary to verify signatures with a given public key. This is @@ -335,15 +300,9 @@ class SignatureAlgorithm(proto.Enum): ECDSA_P384_SHA384 = 10 ECDSA_P521_SHA512 = 11 - public_key_pem = proto.Field( - proto.STRING, - number=1, - ) - signature_algorithm = proto.Field( - proto.ENUM, - number=2, - enum=SignatureAlgorithm, - ) + public_key_pem = proto.Field(proto.STRING, number=1) + + signature_algorithm = proto.Field(proto.ENUM, number=2, enum=SignatureAlgorithm,) class AttestorPublicKey(proto.Message): @@ -382,24 +341,16 @@ class AttestorPublicKey(proto.Message): public key. """ - comment = proto.Field( - proto.STRING, - number=1, - ) - id = proto.Field( - proto.STRING, - number=2, - ) + comment = proto.Field(proto.STRING, number=1) + + id = proto.Field(proto.STRING, number=2) + ascii_armored_pgp_public_key = proto.Field( - proto.STRING, - number=3, - oneof='public_key', + proto.STRING, number=3, oneof="public_key" ) + pkix_public_key = proto.Field( - proto.MESSAGE, - number=5, - oneof='public_key', - message='PkixPublicKey', + proto.MESSAGE, number=5, oneof="public_key", message="PkixPublicKey", ) diff --git a/google/cloud/binaryauthorization_v1beta1/types/service.py b/google/cloud/binaryauthorization_v1beta1/types/service.py index 95e8f7f..c77d251 100644 --- a/google/cloud/binaryauthorization_v1beta1/types/service.py +++ b/google/cloud/binaryauthorization_v1beta1/types/service.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,8 +14,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # + import proto # type: ignore + from google.cloud.binaryauthorization_v1beta1.types import resources @@ -35,6 +38,7 @@ class GetPolicyRequest(proto.Message): r"""Request message for [BinauthzManagementService.GetPolicy][]. + Attributes: name (str): Required. The resource name of the @@ -42,11 +46,12 @@ class GetPolicyRequest(proto.Message): retrieve, in the format ``projects/*/policy``. """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field(proto.STRING, number=1) class UpdatePolicyRequest(proto.Message): r"""Request message for [BinauthzManagementService.UpdatePolicy][]. + Attributes: policy_ (google.cloud.binaryauthorization_v1beta1.types.Policy): Required. A new or updated @@ -62,6 +67,7 @@ class UpdatePolicyRequest(proto.Message): class CreateAttestorRequest(proto.Message): r"""Request message for [BinauthzManagementService.CreateAttestor][]. + Attributes: parent (str): Required. The parent of this @@ -79,13 +85,16 @@ class CreateAttestorRequest(proto.Message): ``projects/*/attestors/*``. """ - parent = proto.Field(proto.STRING, number=1,) - attestor_id = proto.Field(proto.STRING, number=2,) + parent = proto.Field(proto.STRING, number=1) + + attestor_id = proto.Field(proto.STRING, number=2) + attestor = proto.Field(proto.MESSAGE, number=3, message=resources.Attestor,) class GetAttestorRequest(proto.Message): r"""Request message for [BinauthzManagementService.GetAttestor][]. + Attributes: name (str): Required. The name of the @@ -93,11 +102,12 @@ class GetAttestorRequest(proto.Message): to retrieve, in the format ``projects/*/attestors/*``. """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field(proto.STRING, number=1) class UpdateAttestorRequest(proto.Message): r"""Request message for [BinauthzManagementService.UpdateAttestor][]. + Attributes: attestor (google.cloud.binaryauthorization_v1beta1.types.Attestor): Required. The updated @@ -113,6 +123,7 @@ class UpdateAttestorRequest(proto.Message): class ListAttestorsRequest(proto.Message): r"""Request message for [BinauthzManagementService.ListAttestors][]. + Attributes: parent (str): Required. The resource name of the project associated with @@ -131,13 +142,16 @@ class ListAttestorsRequest(proto.Message): method. """ - parent = proto.Field(proto.STRING, number=1,) - page_size = proto.Field(proto.INT32, number=2,) - page_token = proto.Field(proto.STRING, number=3,) + parent = proto.Field(proto.STRING, number=1) + + page_size = proto.Field(proto.INT32, number=2) + + page_token = proto.Field(proto.STRING, number=3) class ListAttestorsResponse(proto.Message): r"""Response message for [BinauthzManagementService.ListAttestors][]. + Attributes: attestors (Sequence[google.cloud.binaryauthorization_v1beta1.types.Attestor]): The list of @@ -157,11 +171,13 @@ def raw_page(self): attestors = proto.RepeatedField( proto.MESSAGE, number=1, message=resources.Attestor, ) - next_page_token = proto.Field(proto.STRING, number=2,) + + next_page_token = proto.Field(proto.STRING, number=2) class DeleteAttestorRequest(proto.Message): r"""Request message for [BinauthzManagementService.DeleteAttestor][]. + Attributes: name (str): Required. The name of the @@ -169,7 +185,7 @@ class DeleteAttestorRequest(proto.Message): to delete, in the format ``projects/*/attestors/*``. """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field(proto.STRING, number=1) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/scripts/fixup_binaryauthorization_v1beta1_keywords.py b/scripts/fixup_binaryauthorization_v1beta1_keywords.py index f6299f4..56d9bd4 100644 --- a/scripts/fixup_binaryauthorization_v1beta1_keywords.py +++ b/scripts/fixup_binaryauthorization_v1beta1_keywords.py @@ -1,5 +1,6 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- + # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,6 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # + import argparse import os import libcst as cst @@ -39,13 +41,14 @@ def partition( class binaryauthorizationCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'create_attestor': ('parent', 'attestor_id', 'attestor', ), - 'delete_attestor': ('name', ), - 'get_attestor': ('name', ), - 'get_policy': ('name', ), - 'list_attestors': ('parent', 'page_size', 'page_token', ), - 'update_attestor': ('attestor', ), - 'update_policy': ('policy_', ), + 'create_attestor': ('parent', 'attestor_id', 'attestor', ), + 'delete_attestor': ('name', ), + 'get_attestor': ('name', ), + 'get_policy': ('name', ), + 'list_attestors': ('parent', 'page_size', 'page_token', ), + 'update_attestor': ('attestor', ), + 'update_policy': ('policy_', ), + } def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: @@ -76,7 +79,7 @@ def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: value=cst.Dict([ cst.DictElement( cst.SimpleString("'{}'".format(name)), -cst.Element(value=arg.value) + cst.Element(value=arg.value) ) # Note: the args + kwargs looks silly, but keep in mind that # the control parameters had to be stripped out, and that diff --git a/synth.metadata b/synth.metadata index 050d164..4d119a5 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,15 +4,15 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/python-binary-authorization.git", - "sha": "82b3583c8dbc897dbb192ffc2051de5169d934c2" + "sha": "996f5010afd4372d625a9accc57647bac46770a8" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "56fc6d43fed71188d7e18f3ca003544646c4ab35", - "internalRef": "366346972" + "sha": "5a04154e7c7c0e98e0e4085f6e2c67bd5bff6ff8", + "internalRef": "371362703" } } ], diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index 4de6597..0000000 --- a/tests/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py deleted file mode 100644 index 4de6597..0000000 --- a/tests/unit/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/tests/unit/gapic/__init__.py b/tests/unit/gapic/__init__.py deleted file mode 100644 index 4de6597..0000000 --- a/tests/unit/gapic/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/tests/unit/gapic/binaryauthorization_v1beta1/__init__.py b/tests/unit/gapic/binaryauthorization_v1beta1/__init__.py index 4de6597..42ffdf2 100644 --- a/tests/unit/gapic/binaryauthorization_v1beta1/__init__.py +++ b/tests/unit/gapic/binaryauthorization_v1beta1/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py b/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py index 4ccb375..cb13870 100644 --- a/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py +++ b/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,9 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # + import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -23,7 +24,6 @@ import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule - from google import auth from google.api_core import client_options from google.api_core import exceptions @@ -44,41 +44,12 @@ from google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1 import ( transports, ) -from google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.transports.base import ( - _API_CORE_VERSION, -) -from google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.binaryauthorization_v1beta1.types import resources from google.cloud.binaryauthorization_v1beta1.types import service from google.oauth2 import service_account from google.protobuf import timestamp_pb2 as timestamp # type: ignore -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: -# - Delete all the api-core and auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - -requires_api_core_lt_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), - reason="This test requires google-api-core < 1.26.0", -) - -requires_api_core_gte_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), - reason="This test requires google-api-core >= 1.26.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -545,17 +516,23 @@ def test_get_policy(transport: str = "grpc", request_type=service.GetPolicyReque description="description_value", global_policy_evaluation_mode=resources.Policy.GlobalPolicyEvaluationMode.ENABLE, ) + response = client.get_policy(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] + assert args[0] == service.GetPolicyRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.Policy) + assert response.name == "name_value" + assert response.description == "description_value" + assert ( response.global_policy_evaluation_mode == resources.Policy.GlobalPolicyEvaluationMode.ENABLE @@ -578,6 +555,7 @@ def test_get_policy_empty_call(): client.get_policy() call.assert_called() _, args, _ = call.mock_calls[0] + assert args[0] == service.GetPolicyRequest() @@ -603,17 +581,22 @@ async def test_get_policy_async( global_policy_evaluation_mode=resources.Policy.GlobalPolicyEvaluationMode.ENABLE, ) ) + response = await client.get_policy(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] + assert args[0] == service.GetPolicyRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.Policy) + assert response.name == "name_value" + assert response.description == "description_value" + assert ( response.global_policy_evaluation_mode == resources.Policy.GlobalPolicyEvaluationMode.ENABLE @@ -633,12 +616,12 @@ def test_get_policy_field_headers(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetPolicyRequest() - request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_policy), "__call__") as call: call.return_value = resources.Policy() + client.get_policy(request) # Establish that the underlying gRPC stub method was called. @@ -660,12 +643,12 @@ async def test_get_policy_field_headers_async(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetPolicyRequest() - request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_policy), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Policy()) + await client.get_policy(request) # Establish that the underlying gRPC stub method was called. @@ -687,6 +670,7 @@ def test_get_policy_flattened(): with mock.patch.object(type(client.transport.get_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Policy() + # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_policy(name="name_value",) @@ -695,6 +679,7 @@ def test_get_policy_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] + assert args[0].name == "name_value" @@ -731,6 +716,7 @@ async def test_get_policy_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] + assert args[0].name == "name_value" @@ -767,17 +753,23 @@ def test_update_policy( description="description_value", global_policy_evaluation_mode=resources.Policy.GlobalPolicyEvaluationMode.ENABLE, ) + response = client.update_policy(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] + assert args[0] == service.UpdatePolicyRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.Policy) + assert response.name == "name_value" + assert response.description == "description_value" + assert ( response.global_policy_evaluation_mode == resources.Policy.GlobalPolicyEvaluationMode.ENABLE @@ -800,6 +792,7 @@ def test_update_policy_empty_call(): client.update_policy() call.assert_called() _, args, _ = call.mock_calls[0] + assert args[0] == service.UpdatePolicyRequest() @@ -825,17 +818,22 @@ async def test_update_policy_async( global_policy_evaluation_mode=resources.Policy.GlobalPolicyEvaluationMode.ENABLE, ) ) + response = await client.update_policy(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] + assert args[0] == service.UpdatePolicyRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.Policy) + assert response.name == "name_value" + assert response.description == "description_value" + assert ( response.global_policy_evaluation_mode == resources.Policy.GlobalPolicyEvaluationMode.ENABLE @@ -855,12 +853,12 @@ def test_update_policy_field_headers(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UpdatePolicyRequest() - request.policy.name = "policy.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_policy), "__call__") as call: call.return_value = resources.Policy() + client.update_policy(request) # Establish that the underlying gRPC stub method was called. @@ -882,12 +880,12 @@ async def test_update_policy_field_headers_async(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UpdatePolicyRequest() - request.policy.name = "policy.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_policy), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Policy()) + await client.update_policy(request) # Establish that the underlying gRPC stub method was called. @@ -909,6 +907,7 @@ def test_update_policy_flattened(): with mock.patch.object(type(client.transport.update_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Policy() + # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.update_policy(policy_=resources.Policy(name="name_value"),) @@ -917,6 +916,7 @@ def test_update_policy_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] + assert args[0].policy_ == resources.Policy(name="name_value") @@ -955,6 +955,7 @@ async def test_update_policy_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] + assert args[0].policy_ == resources.Policy(name="name_value") @@ -993,16 +994,21 @@ def test_create_attestor( note_reference="note_reference_value" ), ) + response = client.create_attestor(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] + assert args[0] == service.CreateAttestorRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.Attestor) + assert response.name == "name_value" + assert response.description == "description_value" @@ -1022,6 +1028,7 @@ def test_create_attestor_empty_call(): client.create_attestor() call.assert_called() _, args, _ = call.mock_calls[0] + assert args[0] == service.CreateAttestorRequest() @@ -1043,16 +1050,20 @@ async def test_create_attestor_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.Attestor(name="name_value", description="description_value",) ) + response = await client.create_attestor(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] + assert args[0] == service.CreateAttestorRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.Attestor) + assert response.name == "name_value" + assert response.description == "description_value" @@ -1069,12 +1080,12 @@ def test_create_attestor_field_headers(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.CreateAttestorRequest() - request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_attestor), "__call__") as call: call.return_value = resources.Attestor() + client.create_attestor(request) # Establish that the underlying gRPC stub method was called. @@ -1096,12 +1107,12 @@ async def test_create_attestor_field_headers_async(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.CreateAttestorRequest() - request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_attestor), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Attestor()) + await client.create_attestor(request) # Establish that the underlying gRPC stub method was called. @@ -1123,6 +1134,7 @@ def test_create_attestor_flattened(): with mock.patch.object(type(client.transport.create_attestor), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Attestor() + # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_attestor( @@ -1135,8 +1147,11 @@ def test_create_attestor_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] + assert args[0].parent == "parent_value" + assert args[0].attestor_id == "attestor_id_value" + assert args[0].attestor == resources.Attestor(name="name_value") @@ -1180,8 +1195,11 @@ async def test_create_attestor_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] + assert args[0].parent == "parent_value" + assert args[0].attestor_id == "attestor_id_value" + assert args[0].attestor == resources.Attestor(name="name_value") @@ -1221,16 +1239,21 @@ def test_get_attestor(transport: str = "grpc", request_type=service.GetAttestorR note_reference="note_reference_value" ), ) + response = client.get_attestor(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] + assert args[0] == service.GetAttestorRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.Attestor) + assert response.name == "name_value" + assert response.description == "description_value" @@ -1250,6 +1273,7 @@ def test_get_attestor_empty_call(): client.get_attestor() call.assert_called() _, args, _ = call.mock_calls[0] + assert args[0] == service.GetAttestorRequest() @@ -1271,16 +1295,20 @@ async def test_get_attestor_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.Attestor(name="name_value", description="description_value",) ) + response = await client.get_attestor(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] + assert args[0] == service.GetAttestorRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.Attestor) + assert response.name == "name_value" + assert response.description == "description_value" @@ -1297,12 +1325,12 @@ def test_get_attestor_field_headers(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetAttestorRequest() - request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_attestor), "__call__") as call: call.return_value = resources.Attestor() + client.get_attestor(request) # Establish that the underlying gRPC stub method was called. @@ -1324,12 +1352,12 @@ async def test_get_attestor_field_headers_async(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetAttestorRequest() - request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_attestor), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Attestor()) + await client.get_attestor(request) # Establish that the underlying gRPC stub method was called. @@ -1351,6 +1379,7 @@ def test_get_attestor_flattened(): with mock.patch.object(type(client.transport.get_attestor), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Attestor() + # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_attestor(name="name_value",) @@ -1359,6 +1388,7 @@ def test_get_attestor_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] + assert args[0].name == "name_value" @@ -1395,6 +1425,7 @@ async def test_get_attestor_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] + assert args[0].name == "name_value" @@ -1433,16 +1464,21 @@ def test_update_attestor( note_reference="note_reference_value" ), ) + response = client.update_attestor(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] + assert args[0] == service.UpdateAttestorRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.Attestor) + assert response.name == "name_value" + assert response.description == "description_value" @@ -1462,6 +1498,7 @@ def test_update_attestor_empty_call(): client.update_attestor() call.assert_called() _, args, _ = call.mock_calls[0] + assert args[0] == service.UpdateAttestorRequest() @@ -1483,16 +1520,20 @@ async def test_update_attestor_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.Attestor(name="name_value", description="description_value",) ) + response = await client.update_attestor(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] + assert args[0] == service.UpdateAttestorRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.Attestor) + assert response.name == "name_value" + assert response.description == "description_value" @@ -1509,12 +1550,12 @@ def test_update_attestor_field_headers(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UpdateAttestorRequest() - request.attestor.name = "attestor.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_attestor), "__call__") as call: call.return_value = resources.Attestor() + client.update_attestor(request) # Establish that the underlying gRPC stub method was called. @@ -1538,12 +1579,12 @@ async def test_update_attestor_field_headers_async(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UpdateAttestorRequest() - request.attestor.name = "attestor.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_attestor), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Attestor()) + await client.update_attestor(request) # Establish that the underlying gRPC stub method was called. @@ -1567,6 +1608,7 @@ def test_update_attestor_flattened(): with mock.patch.object(type(client.transport.update_attestor), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Attestor() + # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.update_attestor(attestor=resources.Attestor(name="name_value"),) @@ -1575,6 +1617,7 @@ def test_update_attestor_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] + assert args[0].attestor == resources.Attestor(name="name_value") @@ -1614,6 +1657,7 @@ async def test_update_attestor_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] + assert args[0].attestor == resources.Attestor(name="name_value") @@ -1649,15 +1693,19 @@ def test_list_attestors( call.return_value = service.ListAttestorsResponse( next_page_token="next_page_token_value", ) + response = client.list_attestors(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] + assert args[0] == service.ListAttestorsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListAttestorsPager) + assert response.next_page_token == "next_page_token_value" @@ -1677,6 +1725,7 @@ def test_list_attestors_empty_call(): client.list_attestors() call.assert_called() _, args, _ = call.mock_calls[0] + assert args[0] == service.ListAttestorsRequest() @@ -1698,15 +1747,18 @@ async def test_list_attestors_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service.ListAttestorsResponse(next_page_token="next_page_token_value",) ) + response = await client.list_attestors(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] + assert args[0] == service.ListAttestorsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListAttestorsAsyncPager) + assert response.next_page_token == "next_page_token_value" @@ -1723,12 +1775,12 @@ def test_list_attestors_field_headers(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ListAttestorsRequest() - request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_attestors), "__call__") as call: call.return_value = service.ListAttestorsResponse() + client.list_attestors(request) # Establish that the underlying gRPC stub method was called. @@ -1750,7 +1802,6 @@ async def test_list_attestors_field_headers_async(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ListAttestorsRequest() - request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1758,6 +1809,7 @@ async def test_list_attestors_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service.ListAttestorsResponse() ) + await client.list_attestors(request) # Establish that the underlying gRPC stub method was called. @@ -1779,6 +1831,7 @@ def test_list_attestors_flattened(): with mock.patch.object(type(client.transport.list_attestors), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = service.ListAttestorsResponse() + # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_attestors(parent="parent_value",) @@ -1787,6 +1840,7 @@ def test_list_attestors_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] + assert args[0].parent == "parent_value" @@ -1825,6 +1879,7 @@ async def test_list_attestors_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] + assert args[0].parent == "parent_value" @@ -2003,11 +2058,13 @@ def test_delete_attestor( with mock.patch.object(type(client.transport.delete_attestor), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None + response = client.delete_attestor(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] + assert args[0] == service.DeleteAttestorRequest() # Establish that the response is the type that we expect. @@ -2030,6 +2087,7 @@ def test_delete_attestor_empty_call(): client.delete_attestor() call.assert_called() _, args, _ = call.mock_calls[0] + assert args[0] == service.DeleteAttestorRequest() @@ -2049,11 +2107,13 @@ async def test_delete_attestor_async( with mock.patch.object(type(client.transport.delete_attestor), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_attestor(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] + assert args[0] == service.DeleteAttestorRequest() # Establish that the response is the type that we expect. @@ -2073,12 +2133,12 @@ def test_delete_attestor_field_headers(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.DeleteAttestorRequest() - request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_attestor), "__call__") as call: call.return_value = None + client.delete_attestor(request) # Establish that the underlying gRPC stub method was called. @@ -2100,12 +2160,12 @@ async def test_delete_attestor_field_headers_async(): # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.DeleteAttestorRequest() - request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_attestor), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_attestor(request) # Establish that the underlying gRPC stub method was called. @@ -2127,6 +2187,7 @@ def test_delete_attestor_flattened(): with mock.patch.object(type(client.transport.delete_attestor), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None + # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.delete_attestor(name="name_value",) @@ -2135,6 +2196,7 @@ def test_delete_attestor_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] + assert args[0].name == "name_value" @@ -2171,6 +2233,7 @@ async def test_delete_attestor_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] + assert args[0].name == "name_value" @@ -2302,32 +2365,10 @@ def test_binauthz_management_service_v1_beta1_base_transport(): getattr(transport, method)(request=object()) -@requires_google_auth_gte_1_25_0 def test_binauthz_management_service_v1_beta1_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( - auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.transports.BinauthzManagementServiceV1Beta1Transport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (credentials.AnonymousCredentials(), None) - transport = transports.BinauthzManagementServiceV1Beta1Transport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=None, - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - -@requires_google_auth_lt_1_25_0 -def test_binauthz_management_service_v1_beta1_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - auth, "load_credentials_from_file", autospec=True + auth, "load_credentials_from_file" ) as load_creds, mock.patch( "google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.transports.BinauthzManagementServiceV1Beta1Transport._prep_wrapped_messages" ) as Transport: @@ -2345,7 +2386,7 @@ def test_binauthz_management_service_v1_beta1_base_transport_with_credentials_fi def test_binauthz_management_service_v1_beta1_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(auth, "default", autospec=True) as adc, mock.patch( + with mock.patch.object(auth, "default") as adc, mock.patch( "google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.transports.BinauthzManagementServiceV1Beta1Transport._prep_wrapped_messages" ) as Transport: Transport.return_value = None @@ -2354,23 +2395,9 @@ def test_binauthz_management_service_v1_beta1_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_binauthz_management_service_v1_beta1_auth_adc(): # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(auth, "default", autospec=True) as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) - BinauthzManagementServiceV1Beta1Client() - adc.assert_called_once_with( - scopes=None, - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - -@requires_google_auth_lt_1_25_0 -def test_binauthz_management_service_v1_beta1_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(auth, "default", autospec=True) as adc: + with mock.patch.object(auth, "default") as adc: adc.return_value = (credentials.AnonymousCredentials(), None) BinauthzManagementServiceV1Beta1Client() adc.assert_called_once_with( @@ -2379,163 +2406,20 @@ def test_binauthz_management_service_v1_beta1_auth_adc_old_google_auth(): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.BinauthzManagementServiceV1Beta1GrpcTransport, - transports.BinauthzManagementServiceV1Beta1GrpcAsyncIOTransport, - ], -) -@requires_google_auth_gte_1_25_0 -def test_binauthz_management_service_v1_beta1_transport_auth_adc(transport_class): +def test_binauthz_management_service_v1_beta1_transport_auth_adc(): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object(auth, "default", autospec=True) as adc: + with mock.patch.object(auth, "default") as adc: adc.return_value = (credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - adc.assert_called_once_with( - scopes=["1", "2"], - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", + transports.BinauthzManagementServiceV1Beta1GrpcTransport( + host="squid.clam.whelk", quota_project_id="octopus" ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.BinauthzManagementServiceV1Beta1GrpcTransport, - transports.BinauthzManagementServiceV1Beta1GrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_binauthz_management_service_v1_beta1_transport_auth_adc_old_google_auth( - transport_class, -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(auth, "default", autospec=True) as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), quota_project_id="octopus", ) -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.BinauthzManagementServiceV1Beta1GrpcTransport, grpc_helpers), - ( - transports.BinauthzManagementServiceV1Beta1GrpcAsyncIOTransport, - grpc_helpers_async, - ), - ], -) -@requires_api_core_gte_1_26_0 -def test_binauthz_management_service_v1_beta1_transport_create_channel( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(auth, "default", autospec=True) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - - create_channel.assert_called_with( - "binaryauthorization.googleapis.com", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - scopes=["1", "2"], - default_host="binaryauthorization.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.BinauthzManagementServiceV1Beta1GrpcTransport, grpc_helpers), - ( - transports.BinauthzManagementServiceV1Beta1GrpcAsyncIOTransport, - grpc_helpers_async, - ), - ], -) -@requires_api_core_lt_1_26_0 -def test_binauthz_management_service_v1_beta1_transport_create_channel_old_api_core( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(auth, "default", autospec=True) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus") - - create_channel.assert_called_with( - "binaryauthorization.googleapis.com", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.BinauthzManagementServiceV1Beta1GrpcTransport, grpc_helpers), - ( - transports.BinauthzManagementServiceV1Beta1GrpcAsyncIOTransport, - grpc_helpers_async, - ), - ], -) -@requires_api_core_lt_1_26_0 -def test_binauthz_management_service_v1_beta1_transport_create_channel_user_scopes( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(auth, "default", autospec=True) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = credentials.AnonymousCredentials() - adc.return_value = (creds, None) - - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - - create_channel.assert_called_with( - "binaryauthorization.googleapis.com", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=["1", "2"], - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -2732,6 +2616,7 @@ def test_binauthz_management_service_v1_beta1_transport_channel_mtls_with_adc( def test_attestor_path(): project = "squid" attestor = "clam" + expected = "projects/{project}/attestors/{attestor}".format( project=project, attestor=attestor, ) @@ -2753,6 +2638,7 @@ def test_parse_attestor_path(): def test_policy_path(): project = "oyster" + expected = "projects/{project}/policy".format(project=project,) actual = BinauthzManagementServiceV1Beta1Client.policy_path(project) assert expected == actual @@ -2771,6 +2657,7 @@ def test_parse_policy_path(): def test_common_billing_account_path(): billing_account = "cuttlefish" + expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -2797,6 +2684,7 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "winkle" + expected = "folders/{folder}".format(folder=folder,) actual = BinauthzManagementServiceV1Beta1Client.common_folder_path(folder) assert expected == actual @@ -2815,6 +2703,7 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "scallop" + expected = "organizations/{organization}".format(organization=organization,) actual = BinauthzManagementServiceV1Beta1Client.common_organization_path( organization @@ -2835,6 +2724,7 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "squid" + expected = "projects/{project}".format(project=project,) actual = BinauthzManagementServiceV1Beta1Client.common_project_path(project) assert expected == actual @@ -2854,6 +2744,7 @@ def test_parse_common_project_path(): def test_common_location_path(): project = "whelk" location = "octopus" + expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) From a11f764be29714a68a34b716115cb93e855961ca Mon Sep 17 00:00:00 2001 From: yoshi-automation Date: Sat, 15 May 2021 04:49:19 +0000 Subject: [PATCH 07/12] fix: add async client to %name_%version/init.py chore: add autogenerated snippets chore: remove auth, policy, and options from the reserved names list feat: support self-signed JWT flow for service accounts chore: enable GAPIC metadata generation chore: sort subpackages in %namespace/%name/init.py PiperOrigin-RevId: 372197450 Source-Author: Google APIs Source-Date: Wed May 5 13:39:02 2021 -0700 Source-Repo: googleapis/googleapis Source-Sha: 83a7e1c8c2f7421ded45ed323eb1fda99ef5ea46 Source-Link: https://github.com/googleapis/googleapis/commit/83a7e1c8c2f7421ded45ed323eb1fda99ef5ea46 --- .coveragerc | 1 - .../binauthz_management_service_v1_beta1.rst | 1 - examples/feature_fragments | 14 + google/cloud/binaryauthorization/__init__.py | 18 +- .../binaryauthorization_v1beta1/__init__.py | 8 +- .../gapic_metadata.json | 93 +++ .../services/__init__.py | 1 - .../__init__.py | 2 - .../async_client.py | 43 +- .../client.py | 44 +- .../pagers.py | 2 - .../transports/__init__.py | 2 - .../transports/base.py | 150 +++-- .../transports/grpc.py | 30 +- .../transports/grpc_asyncio.py | 29 +- .../types/__init__.py | 2 - .../types/resources.py | 50 +- .../types/service.py | 38 +- ...up_binaryauthorization_v1beta1_keywords.py | 19 +- synth.metadata | 9 +- tests/__init__.py | 15 + tests/unit/__init__.py | 15 + tests/unit/gapic/__init__.py | 15 + .../binaryauthorization_v1beta1/__init__.py | 1 - ...st_binauthz_management_service_v1_beta1.py | 567 +++++++++++------- 25 files changed, 704 insertions(+), 465 deletions(-) create mode 100644 examples/feature_fragments create mode 100644 google/cloud/binaryauthorization_v1beta1/gapic_metadata.json create mode 100644 tests/__init__.py create mode 100644 tests/unit/__init__.py create mode 100644 tests/unit/gapic/__init__.py diff --git a/.coveragerc b/.coveragerc index 5ff8242..95c4014 100644 --- a/.coveragerc +++ b/.coveragerc @@ -2,7 +2,6 @@ branch = True [report] -fail_under = 100 show_missing = True omit = google/cloud/binaryauthorization/__init__.py diff --git a/docs/binaryauthorization_v1beta1/binauthz_management_service_v1_beta1.rst b/docs/binaryauthorization_v1beta1/binauthz_management_service_v1_beta1.rst index 5868c89..22016d0 100644 --- a/docs/binaryauthorization_v1beta1/binauthz_management_service_v1_beta1.rst +++ b/docs/binaryauthorization_v1beta1/binauthz_management_service_v1_beta1.rst @@ -5,7 +5,6 @@ BinauthzManagementServiceV1Beta1 :members: :inherited-members: - .. automodule:: google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.pagers :members: :inherited-members: diff --git a/examples/feature_fragments b/examples/feature_fragments new file mode 100644 index 0000000..7d1b624 --- /dev/null +++ b/examples/feature_fragments @@ -0,0 +1,14 @@ + + + + + + + + + + + + + +} diff --git a/google/cloud/binaryauthorization/__init__.py b/google/cloud/binaryauthorization/__init__.py index f082bea..80ed968 100644 --- a/google/cloud/binaryauthorization/__init__.py +++ b/google/cloud/binaryauthorization/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,12 +14,13 @@ # limitations under the License. # -from google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.async_client import ( - BinauthzManagementServiceV1Beta1AsyncClient, -) from google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.client import ( BinauthzManagementServiceV1Beta1Client, ) +from google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.async_client import ( + BinauthzManagementServiceV1Beta1AsyncClient, +) + from google.cloud.binaryauthorization_v1beta1.types.resources import AdmissionRule from google.cloud.binaryauthorization_v1beta1.types.resources import ( AdmissionWhitelistPattern, @@ -42,21 +42,21 @@ from google.cloud.binaryauthorization_v1beta1.types.service import UpdatePolicyRequest __all__ = ( + "BinauthzManagementServiceV1Beta1Client", + "BinauthzManagementServiceV1Beta1AsyncClient", "AdmissionRule", "AdmissionWhitelistPattern", "Attestor", "AttestorPublicKey", - "BinauthzManagementServiceV1Beta1AsyncClient", - "BinauthzManagementServiceV1Beta1Client", + "PkixPublicKey", + "Policy", + "UserOwnedDrydockNote", "CreateAttestorRequest", "DeleteAttestorRequest", "GetAttestorRequest", "GetPolicyRequest", "ListAttestorsRequest", "ListAttestorsResponse", - "PkixPublicKey", - "Policy", "UpdateAttestorRequest", "UpdatePolicyRequest", - "UserOwnedDrydockNote", ) diff --git a/google/cloud/binaryauthorization_v1beta1/__init__.py b/google/cloud/binaryauthorization_v1beta1/__init__.py index 5f14b9c..c775f65 100644 --- a/google/cloud/binaryauthorization_v1beta1/__init__.py +++ b/google/cloud/binaryauthorization_v1beta1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,6 +17,10 @@ from .services.binauthz_management_service_v1_beta1 import ( BinauthzManagementServiceV1Beta1Client, ) +from .services.binauthz_management_service_v1_beta1 import ( + BinauthzManagementServiceV1Beta1AsyncClient, +) + from .types.resources import AdmissionRule from .types.resources import AdmissionWhitelistPattern from .types.resources import Attestor @@ -34,12 +37,12 @@ from .types.service import UpdateAttestorRequest from .types.service import UpdatePolicyRequest - __all__ = ( "AdmissionRule", "AdmissionWhitelistPattern", "Attestor", "AttestorPublicKey", + "BinauthzManagementServiceV1Beta1Client", "CreateAttestorRequest", "DeleteAttestorRequest", "GetAttestorRequest", @@ -51,5 +54,4 @@ "UpdateAttestorRequest", "UpdatePolicyRequest", "UserOwnedDrydockNote", - "BinauthzManagementServiceV1Beta1Client", ) diff --git a/google/cloud/binaryauthorization_v1beta1/gapic_metadata.json b/google/cloud/binaryauthorization_v1beta1/gapic_metadata.json new file mode 100644 index 0000000..8e56955 --- /dev/null +++ b/google/cloud/binaryauthorization_v1beta1/gapic_metadata.json @@ -0,0 +1,93 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.binaryauthorization_v1beta1", + "protoPackage": "google.cloud.binaryauthorization.v1beta1", + "schema": "1.0", + "services": { + "BinauthzManagementServiceV1Beta1": { + "clients": { + "grpc": { + "libraryClient": "BinauthzManagementServiceV1Beta1Client", + "rpcs": { + "CreateAttestor": { + "methods": [ + "create_attestor" + ] + }, + "DeleteAttestor": { + "methods": [ + "delete_attestor" + ] + }, + "GetAttestor": { + "methods": [ + "get_attestor" + ] + }, + "GetPolicy": { + "methods": [ + "get_policy" + ] + }, + "ListAttestors": { + "methods": [ + "list_attestors" + ] + }, + "UpdateAttestor": { + "methods": [ + "update_attestor" + ] + }, + "UpdatePolicy": { + "methods": [ + "update_policy" + ] + } + } + }, + "grpc-async": { + "libraryClient": "BinauthzManagementServiceV1Beta1AsyncClient", + "rpcs": { + "CreateAttestor": { + "methods": [ + "create_attestor" + ] + }, + "DeleteAttestor": { + "methods": [ + "delete_attestor" + ] + }, + "GetAttestor": { + "methods": [ + "get_attestor" + ] + }, + "GetPolicy": { + "methods": [ + "get_policy" + ] + }, + "ListAttestors": { + "methods": [ + "list_attestors" + ] + }, + "UpdateAttestor": { + "methods": [ + "update_attestor" + ] + }, + "UpdatePolicy": { + "methods": [ + "update_policy" + ] + } + } + } + } + } + } +} diff --git a/google/cloud/binaryauthorization_v1beta1/services/__init__.py b/google/cloud/binaryauthorization_v1beta1/services/__init__.py index 42ffdf2..4de6597 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/__init__.py +++ b/google/cloud/binaryauthorization_v1beta1/services/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/__init__.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/__init__.py index f832d0c..e133615 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/__init__.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .client import BinauthzManagementServiceV1Beta1Client from .async_client import BinauthzManagementServiceV1Beta1AsyncClient diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py index c8c2474..b4b994a 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict import functools import re @@ -22,10 +20,10 @@ import pkg_resources import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore from google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1 import ( @@ -33,8 +31,7 @@ ) from google.cloud.binaryauthorization_v1beta1.types import resources from google.cloud.binaryauthorization_v1beta1.types import service -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import ( BinauthzManagementServiceV1Beta1Transport, DEFAULT_CLIENT_INFO, @@ -68,35 +65,30 @@ class BinauthzManagementServiceV1Beta1AsyncClient: parse_policy_path = staticmethod( BinauthzManagementServiceV1Beta1Client.parse_policy_path ) - common_billing_account_path = staticmethod( BinauthzManagementServiceV1Beta1Client.common_billing_account_path ) parse_common_billing_account_path = staticmethod( BinauthzManagementServiceV1Beta1Client.parse_common_billing_account_path ) - common_folder_path = staticmethod( BinauthzManagementServiceV1Beta1Client.common_folder_path ) parse_common_folder_path = staticmethod( BinauthzManagementServiceV1Beta1Client.parse_common_folder_path ) - common_organization_path = staticmethod( BinauthzManagementServiceV1Beta1Client.common_organization_path ) parse_common_organization_path = staticmethod( BinauthzManagementServiceV1Beta1Client.parse_common_organization_path ) - common_project_path = staticmethod( BinauthzManagementServiceV1Beta1Client.common_project_path ) parse_common_project_path = staticmethod( BinauthzManagementServiceV1Beta1Client.parse_common_project_path ) - common_location_path = staticmethod( BinauthzManagementServiceV1Beta1Client.common_location_path ) @@ -153,7 +145,7 @@ def transport(self) -> BinauthzManagementServiceV1Beta1Transport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[ str, BinauthzManagementServiceV1Beta1Transport ] = "grpc_asyncio", @@ -192,7 +184,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = BinauthzManagementServiceV1Beta1Client( credentials=credentials, transport=transport, @@ -235,7 +226,6 @@ async def get_policy( This corresponds to the ``name`` 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. @@ -262,7 +252,6 @@ async def get_policy( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -299,7 +288,7 @@ async def update_policy( self, request: service.UpdatePolicyRequest = None, *, - policy_: resources.Policy = None, + policy: resources.Policy = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -317,7 +306,7 @@ async def update_policy( request (:class:`google.cloud.binaryauthorization_v1beta1.types.UpdatePolicyRequest`): The request object. Request message for [BinauthzManagementService.UpdatePolicy][]. - policy_ (:class:`google.cloud.binaryauthorization_v1beta1.types.Policy`): + policy (:class:`google.cloud.binaryauthorization_v1beta1.types.Policy`): Required. A new or updated [policy][google.cloud.binaryauthorization.v1beta1.Policy] value. The service will overwrite the [policy @@ -325,10 +314,9 @@ async def update_policy( field with the resource name in the request URL, in the format ``projects/*/policy``. - This corresponds to the ``policy_`` field + This corresponds to the ``policy`` 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. @@ -344,7 +332,7 @@ async def update_policy( # 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([policy_]) + has_flattened_params = any([policy]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -355,9 +343,8 @@ async def update_policy( # If we have keyword arguments corresponding to fields on the # request, apply these. - - if policy_ is not None: - request.policy_ = policy_ + if policy is not None: + request.policy = policy # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -441,7 +428,6 @@ async def create_attestor( This corresponds to the ``attestor`` 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. @@ -469,7 +455,6 @@ async def create_attestor( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if attestor_id is not None: @@ -524,7 +509,6 @@ async def get_attestor( This corresponds to the ``name`` 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. @@ -552,7 +536,6 @@ async def get_attestor( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -615,7 +598,6 @@ async def update_attestor( This corresponds to the ``attestor`` 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. @@ -643,7 +625,6 @@ async def update_attestor( # If we have keyword arguments corresponding to fields on the # request, apply these. - if attestor is not None: request.attestor = attestor @@ -704,7 +685,6 @@ async def list_attestors( This corresponds to the ``parent`` 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. @@ -734,7 +714,6 @@ async def list_attestors( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -800,7 +779,6 @@ async def delete_attestor( This corresponds to the ``name`` 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. @@ -821,7 +799,6 @@ async def delete_attestor( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py index 4dbbd25..b2164e1 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from distutils import util import os @@ -23,10 +21,10 @@ import pkg_resources from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore @@ -37,8 +35,7 @@ ) from google.cloud.binaryauthorization_v1beta1.types import resources from google.cloud.binaryauthorization_v1beta1.types import service -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import ( BinauthzManagementServiceV1Beta1Transport, DEFAULT_CLIENT_INFO, @@ -263,7 +260,7 @@ def parse_common_location_path(path: str) -> Dict[str, str]: def __init__( self, *, - credentials: Optional[credentials.Credentials] = None, + credentials: Optional[ga_credentials.Credentials] = None, transport: Union[str, BinauthzManagementServiceV1Beta1Transport, None] = None, client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, @@ -408,7 +405,6 @@ def get_policy( This corresponds to the ``name`` 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. @@ -437,10 +433,8 @@ def get_policy( # there are no flattened fields. if not isinstance(request, service.GetPolicyRequest): request = service.GetPolicyRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -464,7 +458,7 @@ def update_policy( self, request: service.UpdatePolicyRequest = None, *, - policy_: resources.Policy = None, + policy: resources.Policy = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -482,7 +476,7 @@ def update_policy( request (google.cloud.binaryauthorization_v1beta1.types.UpdatePolicyRequest): The request object. Request message for [BinauthzManagementService.UpdatePolicy][]. - policy_ (google.cloud.binaryauthorization_v1beta1.types.Policy): + policy (google.cloud.binaryauthorization_v1beta1.types.Policy): Required. A new or updated [policy][google.cloud.binaryauthorization.v1beta1.Policy] value. The service will overwrite the [policy @@ -490,10 +484,9 @@ def update_policy( field with the resource name in the request URL, in the format ``projects/*/policy``. - This corresponds to the ``policy_`` field + This corresponds to the ``policy`` 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. @@ -509,7 +502,7 @@ def update_policy( # 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([policy_]) + has_flattened_params = any([policy]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -522,12 +515,10 @@ def update_policy( # there are no flattened fields. if not isinstance(request, service.UpdatePolicyRequest): request = service.UpdatePolicyRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - - if policy_ is not None: - request.policy_ = policy_ + if policy is not None: + request.policy = policy # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -598,7 +589,6 @@ def create_attestor( This corresponds to the ``attestor`` 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. @@ -628,10 +618,8 @@ def create_attestor( # there are no flattened fields. if not isinstance(request, service.CreateAttestorRequest): request = service.CreateAttestorRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if attestor_id is not None: @@ -682,7 +670,6 @@ def get_attestor( This corresponds to the ``name`` 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. @@ -712,10 +699,8 @@ def get_attestor( # there are no flattened fields. if not isinstance(request, service.GetAttestorRequest): request = service.GetAttestorRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -765,7 +750,6 @@ def update_attestor( This corresponds to the ``attestor`` 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. @@ -795,10 +779,8 @@ def update_attestor( # there are no flattened fields. if not isinstance(request, service.UpdateAttestorRequest): request = service.UpdateAttestorRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if attestor is not None: request.attestor = attestor @@ -846,7 +828,6 @@ def list_attestors( This corresponds to the ``parent`` 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. @@ -878,10 +859,8 @@ def list_attestors( # there are no flattened fields. if not isinstance(request, service.ListAttestorsRequest): request = service.ListAttestorsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -934,7 +913,6 @@ def delete_attestor( This corresponds to the ``name`` 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. @@ -957,10 +935,8 @@ def delete_attestor( # there are no flattened fields. if not isinstance(request, service.DeleteAttestorRequest): request = service.DeleteAttestorRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/pagers.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/pagers.py index 42c4659..9aecf4b 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/pagers.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/pagers.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from typing import ( Any, AsyncIterable, diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/__init__.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/__init__.py index 78aef3f..bf3c24d 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/__init__.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from typing import Dict, Type diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/base.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/base.py index 9bc0a22..6a3d84a 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/base.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/base.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,21 +13,21 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import abc -import typing +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import packaging.version import pkg_resources -from google import auth # type: ignore -from google.api_core import exceptions # type: ignore +import google.auth # type: ignore +import google.api_core # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.cloud.binaryauthorization_v1beta1.types import resources from google.cloud.binaryauthorization_v1beta1.types import service -from google.protobuf import empty_pb2 as empty # type: ignore - +from google.protobuf import empty_pb2 # type: ignore try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -39,27 +38,41 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +try: + # google.auth.__version__ was added in 1.26.0 + _GOOGLE_AUTH_VERSION = google.auth.__version__ +except AttributeError: + try: # try pkg_resources if it is available + _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version + except pkg_resources.DistributionNotFound: # pragma: NO COVER + _GOOGLE_AUTH_VERSION = None + +_API_CORE_VERSION = google.api_core.__version__ + class BinauthzManagementServiceV1Beta1Transport(abc.ABC): """Abstract transport class for BinauthzManagementServiceV1Beta1.""" AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + DEFAULT_HOST: str = "binaryauthorization.googleapis.com" + def __init__( self, *, - host: str = "binaryauthorization.googleapis.com", - credentials: credentials.Credentials = None, - credentials_file: typing.Optional[str] = None, - scopes: typing.Optional[typing.Sequence[str]] = AUTH_SCOPES, - quota_project_id: typing.Optional[str] = None, + host: str = DEFAULT_HOST, + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, **kwargs, ) -> None: """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -68,7 +81,7 @@ def __init__( credentials_file (Optional[str]): A file with credentials that can be loaded with :func:`google.auth.load_credentials_from_file`. This argument is mutually exclusive with credentials. - scope (Optional[Sequence[str]]): A list of scopes. + scopes (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -82,29 +95,76 @@ def __init__( host += ":443" self._host = host + scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + # Save the scopes. self._scopes = scopes or self.AUTH_SCOPES # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: - raise exceptions.DuplicateCredentialArgs( + raise core_exceptions.DuplicateCredentialArgs( "'credentials_file' and 'credentials' are mutually exclusive" ) if credentials_file is not None: - credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) elif credentials is None: - credentials, _ = auth.default( - scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.default( + **scopes_kwargs, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials + # TODO(busunkim): These two class methods are in the base transport + # to avoid duplicating code across the transport classes. These functions + # should be deleted once the minimum required versions of google-api-core + # and google-auth are increased. + + # TODO: Remove this function once google-auth >= 1.25.0 is required + @classmethod + def _get_scopes_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Optional[Sequence[str]]]: + """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" + + scopes_kwargs = {} + + if _GOOGLE_AUTH_VERSION and ( + packaging.version.parse(_GOOGLE_AUTH_VERSION) + >= packaging.version.parse("1.25.0") + ): + scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} + else: + scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} + + return scopes_kwargs + + # TODO: Remove this function once google-api-core >= 1.26.0 is required + @classmethod + def _get_self_signed_jwt_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Union[Optional[Sequence[str]], str]]: + """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" + + self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} + + if _API_CORE_VERSION and ( + packaging.version.parse(_API_CORE_VERSION) + >= packaging.version.parse("1.26.0") + ): + self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES + self_signed_jwt_kwargs["scopes"] = scopes + self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST + else: + self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES + + return self_signed_jwt_kwargs + def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -115,7 +175,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -129,7 +190,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -146,7 +208,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -160,7 +223,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -174,7 +238,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -188,7 +253,8 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -200,66 +266,62 @@ def _prep_wrapped_messages(self, client_info): @property def get_policy( self, - ) -> typing.Callable[ - [service.GetPolicyRequest], - typing.Union[resources.Policy, typing.Awaitable[resources.Policy]], + ) -> Callable[ + [service.GetPolicyRequest], Union[resources.Policy, Awaitable[resources.Policy]] ]: raise NotImplementedError() @property def update_policy( self, - ) -> typing.Callable[ + ) -> Callable[ [service.UpdatePolicyRequest], - typing.Union[resources.Policy, typing.Awaitable[resources.Policy]], + Union[resources.Policy, Awaitable[resources.Policy]], ]: raise NotImplementedError() @property def create_attestor( self, - ) -> typing.Callable[ + ) -> Callable[ [service.CreateAttestorRequest], - typing.Union[resources.Attestor, typing.Awaitable[resources.Attestor]], + Union[resources.Attestor, Awaitable[resources.Attestor]], ]: raise NotImplementedError() @property def get_attestor( self, - ) -> typing.Callable[ + ) -> Callable[ [service.GetAttestorRequest], - typing.Union[resources.Attestor, typing.Awaitable[resources.Attestor]], + Union[resources.Attestor, Awaitable[resources.Attestor]], ]: raise NotImplementedError() @property def update_attestor( self, - ) -> typing.Callable[ + ) -> Callable[ [service.UpdateAttestorRequest], - typing.Union[resources.Attestor, typing.Awaitable[resources.Attestor]], + Union[resources.Attestor, Awaitable[resources.Attestor]], ]: raise NotImplementedError() @property def list_attestors( self, - ) -> typing.Callable[ + ) -> Callable[ [service.ListAttestorsRequest], - typing.Union[ - service.ListAttestorsResponse, - typing.Awaitable[service.ListAttestorsResponse], - ], + Union[service.ListAttestorsResponse, Awaitable[service.ListAttestorsResponse]], ]: raise NotImplementedError() @property def delete_attestor( self, - ) -> typing.Callable[ + ) -> Callable[ [service.DeleteAttestorRequest], - typing.Union[empty.Empty, typing.Awaitable[empty.Empty]], + Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]], ]: raise NotImplementedError() diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py index e2a2f5b..1c0b0da 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,22 +13,20 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple +from typing import Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import grpc_helpers # type: ignore from google.api_core import gapic_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore import grpc # type: ignore from google.cloud.binaryauthorization_v1beta1.types import resources from google.cloud.binaryauthorization_v1beta1.types import service -from google.protobuf import empty_pb2 as empty # type: ignore - +from google.protobuf import empty_pb2 # type: ignore from .base import BinauthzManagementServiceV1Beta1Transport, DEFAULT_CLIENT_INFO @@ -60,7 +57,7 @@ def __init__( self, *, host: str = "binaryauthorization.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Sequence[str] = None, channel: grpc.Channel = None, @@ -74,7 +71,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -184,7 +182,7 @@ def __init__( def create_channel( cls, host: str = "binaryauthorization.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -215,13 +213,15 @@ def create_channel( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -423,7 +423,9 @@ def list_attestors( return self._stubs["list_attestors"] @property - def delete_attestor(self) -> Callable[[service.DeleteAttestorRequest], empty.Empty]: + def delete_attestor( + self, + ) -> Callable[[service.DeleteAttestorRequest], empty_pb2.Empty]: r"""Return a callable for the delete attestor method over gRPC. Deletes an @@ -446,7 +448,7 @@ def delete_attestor(self) -> Callable[[service.DeleteAttestorRequest], empty.Emp self._stubs["delete_attestor"] = self.grpc_channel.unary_unary( "/google.cloud.binaryauthorization.v1beta1.BinauthzManagementServiceV1Beta1/DeleteAttestor", request_serializer=service.DeleteAttestorRequest.serialize, - response_deserializer=empty.Empty.FromString, + response_deserializer=empty_pb2.Empty.FromString, ) return self._stubs["delete_attestor"] diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py index 4b621da..3b11c32 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,23 +13,21 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import gapic_v1 # type: ignore from google.api_core import grpc_helpers_async # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore from google.cloud.binaryauthorization_v1beta1.types import resources from google.cloud.binaryauthorization_v1beta1.types import service -from google.protobuf import empty_pb2 as empty # type: ignore - +from google.protobuf import empty_pb2 # type: ignore from .base import BinauthzManagementServiceV1Beta1Transport, DEFAULT_CLIENT_INFO from .grpc import BinauthzManagementServiceV1Beta1GrpcTransport @@ -63,7 +60,7 @@ class BinauthzManagementServiceV1Beta1GrpcAsyncIOTransport( def create_channel( cls, host: str = "binaryauthorization.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -90,13 +87,15 @@ def create_channel( Returns: aio.Channel: A gRPC AsyncIO channel object. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -104,7 +103,7 @@ def __init__( self, *, host: str = "binaryauthorization.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, channel: aio.Channel = None, @@ -118,7 +117,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -176,7 +176,6 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - else: if api_mtls_endpoint: host = api_mtls_endpoint @@ -433,7 +432,7 @@ def list_attestors( @property def delete_attestor( self, - ) -> Callable[[service.DeleteAttestorRequest], Awaitable[empty.Empty]]: + ) -> Callable[[service.DeleteAttestorRequest], Awaitable[empty_pb2.Empty]]: r"""Return a callable for the delete attestor method over gRPC. Deletes an @@ -456,7 +455,7 @@ def delete_attestor( self._stubs["delete_attestor"] = self.grpc_channel.unary_unary( "/google.cloud.binaryauthorization.v1beta1.BinauthzManagementServiceV1Beta1/DeleteAttestor", request_serializer=service.DeleteAttestorRequest.serialize, - response_deserializer=empty.Empty.FromString, + response_deserializer=empty_pb2.Empty.FromString, ) return self._stubs["delete_attestor"] diff --git a/google/cloud/binaryauthorization_v1beta1/types/__init__.py b/google/cloud/binaryauthorization_v1beta1/types/__init__.py index b4424d4..122112d 100644 --- a/google/cloud/binaryauthorization_v1beta1/types/__init__.py +++ b/google/cloud/binaryauthorization_v1beta1/types/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .resources import ( AdmissionRule, AdmissionWhitelistPattern, diff --git a/google/cloud/binaryauthorization_v1beta1/types/resources.py b/google/cloud/binaryauthorization_v1beta1/types/resources.py index 7866476..a04d681 100644 --- a/google/cloud/binaryauthorization_v1beta1/types/resources.py +++ b/google/cloud/binaryauthorization_v1beta1/types/resources.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,11 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -83,27 +80,21 @@ class GlobalPolicyEvaluationMode(proto.Enum): ENABLE = 1 DISABLE = 2 - name = proto.Field(proto.STRING, number=1) - - description = proto.Field(proto.STRING, number=6) - + name = proto.Field(proto.STRING, number=1,) + description = proto.Field(proto.STRING, number=6,) global_policy_evaluation_mode = proto.Field( proto.ENUM, number=7, enum=GlobalPolicyEvaluationMode, ) - admission_whitelist_patterns = proto.RepeatedField( proto.MESSAGE, number=2, message="AdmissionWhitelistPattern", ) - cluster_admission_rules = proto.MapField( proto.STRING, proto.MESSAGE, number=3, message="AdmissionRule", ) - default_admission_rule = proto.Field( proto.MESSAGE, number=4, message="AdmissionRule", ) - - update_time = proto.Field(proto.MESSAGE, number=5, message=timestamp.Timestamp,) + update_time = proto.Field(proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp,) class AdmissionWhitelistPattern(proto.Message): @@ -120,7 +111,7 @@ class AdmissionWhitelistPattern(proto.Message): ``registry/`` part. """ - name_pattern = proto.Field(proto.STRING, number=1) + name_pattern = proto.Field(proto.STRING, number=1,) class AdmissionRule(proto.Message): @@ -173,9 +164,7 @@ class EnforcementMode(proto.Enum): DRYRUN_AUDIT_LOG_ONLY = 2 evaluation_mode = proto.Field(proto.ENUM, number=1, enum=EvaluationMode,) - - require_attestations_by = proto.RepeatedField(proto.STRING, number=2) - + require_attestations_by = proto.RepeatedField(proto.STRING, number=2,) enforcement_mode = proto.Field(proto.ENUM, number=3, enum=EnforcementMode,) @@ -199,15 +188,12 @@ class Attestor(proto.Message): updated. """ - name = proto.Field(proto.STRING, number=1) - - description = proto.Field(proto.STRING, number=6) - + name = proto.Field(proto.STRING, number=1,) + description = proto.Field(proto.STRING, number=6,) user_owned_drydock_note = proto.Field( proto.MESSAGE, number=3, oneof="attestor_type", message="UserOwnedDrydockNote", ) - - update_time = proto.Field(proto.MESSAGE, number=4, message=timestamp.Timestamp,) + update_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) class UserOwnedDrydockNote(proto.Message): @@ -251,13 +237,11 @@ class UserOwnedDrydockNote(proto.Message): email based on a different naming pattern. """ - note_reference = proto.Field(proto.STRING, number=1) - + note_reference = proto.Field(proto.STRING, number=1,) public_keys = proto.RepeatedField( proto.MESSAGE, number=2, message="AttestorPublicKey", ) - - delegation_service_account_email = proto.Field(proto.STRING, number=3) + delegation_service_account_email = proto.Field(proto.STRING, number=3,) class PkixPublicKey(proto.Message): @@ -300,8 +284,7 @@ class SignatureAlgorithm(proto.Enum): ECDSA_P384_SHA384 = 10 ECDSA_P521_SHA512 = 11 - public_key_pem = proto.Field(proto.STRING, number=1) - + public_key_pem = proto.Field(proto.STRING, number=1,) signature_algorithm = proto.Field(proto.ENUM, number=2, enum=SignatureAlgorithm,) @@ -341,14 +324,11 @@ class AttestorPublicKey(proto.Message): public key. """ - comment = proto.Field(proto.STRING, number=1) - - id = proto.Field(proto.STRING, number=2) - + comment = proto.Field(proto.STRING, number=1,) + id = proto.Field(proto.STRING, number=2,) ascii_armored_pgp_public_key = proto.Field( - proto.STRING, number=3, oneof="public_key" + proto.STRING, number=3, oneof="public_key", ) - pkix_public_key = proto.Field( proto.MESSAGE, number=5, oneof="public_key", message="PkixPublicKey", ) diff --git a/google/cloud/binaryauthorization_v1beta1/types/service.py b/google/cloud/binaryauthorization_v1beta1/types/service.py index c77d251..ccf4e94 100644 --- a/google/cloud/binaryauthorization_v1beta1/types/service.py +++ b/google/cloud/binaryauthorization_v1beta1/types/service.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - from google.cloud.binaryauthorization_v1beta1.types import resources @@ -38,7 +35,6 @@ class GetPolicyRequest(proto.Message): r"""Request message for [BinauthzManagementService.GetPolicy][]. - Attributes: name (str): Required. The resource name of the @@ -46,14 +42,13 @@ class GetPolicyRequest(proto.Message): retrieve, in the format ``projects/*/policy``. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class UpdatePolicyRequest(proto.Message): r"""Request message for [BinauthzManagementService.UpdatePolicy][]. - Attributes: - policy_ (google.cloud.binaryauthorization_v1beta1.types.Policy): + policy (google.cloud.binaryauthorization_v1beta1.types.Policy): Required. A new or updated [policy][google.cloud.binaryauthorization.v1beta1.Policy] value. The service will overwrite the [policy @@ -62,12 +57,11 @@ class UpdatePolicyRequest(proto.Message): format ``projects/*/policy``. """ - policy_ = proto.Field(proto.MESSAGE, number=1, message=resources.Policy,) + policy = proto.Field(proto.MESSAGE, number=1, message=resources.Policy,) class CreateAttestorRequest(proto.Message): r"""Request message for [BinauthzManagementService.CreateAttestor][]. - Attributes: parent (str): Required. The parent of this @@ -85,16 +79,13 @@ class CreateAttestorRequest(proto.Message): ``projects/*/attestors/*``. """ - parent = proto.Field(proto.STRING, number=1) - - attestor_id = proto.Field(proto.STRING, number=2) - + parent = proto.Field(proto.STRING, number=1,) + attestor_id = proto.Field(proto.STRING, number=2,) attestor = proto.Field(proto.MESSAGE, number=3, message=resources.Attestor,) class GetAttestorRequest(proto.Message): r"""Request message for [BinauthzManagementService.GetAttestor][]. - Attributes: name (str): Required. The name of the @@ -102,12 +93,11 @@ class GetAttestorRequest(proto.Message): to retrieve, in the format ``projects/*/attestors/*``. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class UpdateAttestorRequest(proto.Message): r"""Request message for [BinauthzManagementService.UpdateAttestor][]. - Attributes: attestor (google.cloud.binaryauthorization_v1beta1.types.Attestor): Required. The updated @@ -123,7 +113,6 @@ class UpdateAttestorRequest(proto.Message): class ListAttestorsRequest(proto.Message): r"""Request message for [BinauthzManagementService.ListAttestors][]. - Attributes: parent (str): Required. The resource name of the project associated with @@ -142,16 +131,13 @@ class ListAttestorsRequest(proto.Message): method. """ - parent = proto.Field(proto.STRING, number=1) - - page_size = proto.Field(proto.INT32, number=2) - - page_token = proto.Field(proto.STRING, number=3) + parent = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=2,) + page_token = proto.Field(proto.STRING, number=3,) class ListAttestorsResponse(proto.Message): r"""Response message for [BinauthzManagementService.ListAttestors][]. - Attributes: attestors (Sequence[google.cloud.binaryauthorization_v1beta1.types.Attestor]): The list of @@ -171,13 +157,11 @@ def raw_page(self): attestors = proto.RepeatedField( proto.MESSAGE, number=1, message=resources.Attestor, ) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class DeleteAttestorRequest(proto.Message): r"""Request message for [BinauthzManagementService.DeleteAttestor][]. - Attributes: name (str): Required. The name of the @@ -185,7 +169,7 @@ class DeleteAttestorRequest(proto.Message): to delete, in the format ``projects/*/attestors/*``. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/scripts/fixup_binaryauthorization_v1beta1_keywords.py b/scripts/fixup_binaryauthorization_v1beta1_keywords.py index 56d9bd4..95b795b 100644 --- a/scripts/fixup_binaryauthorization_v1beta1_keywords.py +++ b/scripts/fixup_binaryauthorization_v1beta1_keywords.py @@ -1,6 +1,5 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import argparse import os import libcst as cst @@ -41,14 +39,13 @@ def partition( class binaryauthorizationCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'create_attestor': ('parent', 'attestor_id', 'attestor', ), - 'delete_attestor': ('name', ), - 'get_attestor': ('name', ), - 'get_policy': ('name', ), - 'list_attestors': ('parent', 'page_size', 'page_token', ), - 'update_attestor': ('attestor', ), - 'update_policy': ('policy_', ), - + 'create_attestor': ('parent', 'attestor_id', 'attestor', ), + 'delete_attestor': ('name', ), + 'get_attestor': ('name', ), + 'get_policy': ('name', ), + 'list_attestors': ('parent', 'page_size', 'page_token', ), + 'update_attestor': ('attestor', ), + 'update_policy': ('policy', ), } def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: @@ -79,7 +76,7 @@ def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: value=cst.Dict([ cst.DictElement( cst.SimpleString("'{}'".format(name)), - cst.Element(value=arg.value) +cst.Element(value=arg.value) ) # Note: the args + kwargs looks silly, but keep in mind that # the control parameters had to be stripped out, and that diff --git a/synth.metadata b/synth.metadata index 4d119a5..227faa9 100644 --- a/synth.metadata +++ b/synth.metadata @@ -11,8 +11,8 @@ "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "5a04154e7c7c0e98e0e4085f6e2c67bd5bff6ff8", - "internalRef": "371362703" + "sha": "83a7e1c8c2f7421ded45ed323eb1fda99ef5ea46", + "internalRef": "372197450" } } ], @@ -91,9 +91,11 @@ "docs/binaryauthorization_v1beta1/types.rst", "docs/conf.py", "docs/multiprocessing.rst", + "examples/feature_fragments", "google/cloud/binaryauthorization/__init__.py", "google/cloud/binaryauthorization/py.typed", "google/cloud/binaryauthorization_v1beta1/__init__.py", + "google/cloud/binaryauthorization_v1beta1/gapic_metadata.json", "google/cloud/binaryauthorization_v1beta1/py.typed", "google/cloud/binaryauthorization_v1beta1/services/__init__.py", "google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/__init__.py", @@ -120,6 +122,9 @@ "scripts/readme-gen/templates/install_portaudio.tmpl.rst", "setup.cfg", "testing/.gitignore", + "tests/__init__.py", + "tests/unit/__init__.py", + "tests/unit/gapic/__init__.py", "tests/unit/gapic/binaryauthorization_v1beta1/__init__.py", "tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py" ] diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..4de6597 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py new file mode 100644 index 0000000..4de6597 --- /dev/null +++ b/tests/unit/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/tests/unit/gapic/__init__.py b/tests/unit/gapic/__init__.py new file mode 100644 index 0000000..4de6597 --- /dev/null +++ b/tests/unit/gapic/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/tests/unit/gapic/binaryauthorization_v1beta1/__init__.py b/tests/unit/gapic/binaryauthorization_v1beta1/__init__.py index 42ffdf2..4de6597 100644 --- a/tests/unit/gapic/binaryauthorization_v1beta1/__init__.py +++ b/tests/unit/gapic/binaryauthorization_v1beta1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py b/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py index cb13870..3873031 100644 --- a/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py +++ b/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import os import mock +import packaging.version import grpc from grpc.experimental import aio @@ -24,13 +23,13 @@ import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule -from google import auth + from google.api_core import client_options -from google.api_core import exceptions +from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async -from google.auth import credentials +from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1 import ( BinauthzManagementServiceV1Beta1AsyncClient, @@ -44,10 +43,40 @@ from google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1 import ( transports, ) +from google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.transports.base import ( + _API_CORE_VERSION, +) +from google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.transports.base import ( + _GOOGLE_AUTH_VERSION, +) from google.cloud.binaryauthorization_v1beta1.types import resources from google.cloud.binaryauthorization_v1beta1.types import service from google.oauth2 import service_account -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +import google.auth + + +# TODO(busunkim): Once google-api-core >= 1.26.0 is required: +# - Delete all the api-core and auth "less than" test cases +# - Delete these pytest markers (Make the "greater than or equal to" tests the default). +requires_google_auth_lt_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), + reason="This test requires google-auth < 1.25.0", +) +requires_google_auth_gte_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), + reason="This test requires google-auth >= 1.25.0", +) + +requires_api_core_lt_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), + reason="This test requires google-api-core < 1.26.0", +) + +requires_api_core_gte_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), + reason="This test requires google-api-core >= 1.26.0", +) def client_cert_source_callback(): @@ -113,7 +142,7 @@ def test__get_default_mtls_endpoint(): def test_binauthz_management_service_v1_beta1_client_from_service_account_info( client_class, ): - creds = credentials.AnonymousCredentials() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -136,7 +165,7 @@ def test_binauthz_management_service_v1_beta1_client_from_service_account_info( def test_binauthz_management_service_v1_beta1_client_from_service_account_file( client_class, ): - creds = credentials.AnonymousCredentials() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -195,7 +224,7 @@ def test_binauthz_management_service_v1_beta1_client_client_options( with mock.patch.object( BinauthzManagementServiceV1Beta1Client, "get_transport_class" ) as gtc: - transport = transport_class(credentials=credentials.AnonymousCredentials()) + transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) client = client_class(transport=transport) gtc.assert_not_called() @@ -501,7 +530,7 @@ def test_binauthz_management_service_v1_beta1_client_client_options_from_dict(): def test_get_policy(transport: str = "grpc", request_type=service.GetPolicyRequest): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -516,23 +545,17 @@ def test_get_policy(transport: str = "grpc", request_type=service.GetPolicyReque description="description_value", global_policy_evaluation_mode=resources.Policy.GlobalPolicyEvaluationMode.ENABLE, ) - response = client.get_policy(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.GetPolicyRequest() # Establish that the response is the type that we expect. - assert isinstance(response, resources.Policy) - assert response.name == "name_value" - assert response.description == "description_value" - assert ( response.global_policy_evaluation_mode == resources.Policy.GlobalPolicyEvaluationMode.ENABLE @@ -547,7 +570,7 @@ def test_get_policy_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -555,7 +578,6 @@ def test_get_policy_empty_call(): client.get_policy() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.GetPolicyRequest() @@ -564,7 +586,7 @@ async def test_get_policy_async( transport: str = "grpc_asyncio", request_type=service.GetPolicyRequest ): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -581,22 +603,17 @@ async def test_get_policy_async( global_policy_evaluation_mode=resources.Policy.GlobalPolicyEvaluationMode.ENABLE, ) ) - response = await client.get_policy(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.GetPolicyRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.Policy) - assert response.name == "name_value" - assert response.description == "description_value" - assert ( response.global_policy_evaluation_mode == resources.Policy.GlobalPolicyEvaluationMode.ENABLE @@ -610,18 +627,18 @@ async def test_get_policy_async_from_dict(): def test_get_policy_field_headers(): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetPolicyRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_policy), "__call__") as call: call.return_value = resources.Policy() - client.get_policy(request) # Establish that the underlying gRPC stub method was called. @@ -637,18 +654,18 @@ def test_get_policy_field_headers(): @pytest.mark.asyncio async def test_get_policy_field_headers_async(): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetPolicyRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_policy), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Policy()) - await client.get_policy(request) # Establish that the underlying gRPC stub method was called. @@ -663,14 +680,13 @@ async def test_get_policy_field_headers_async(): def test_get_policy_flattened(): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Policy() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_policy(name="name_value",) @@ -679,13 +695,12 @@ def test_get_policy_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_policy_flattened_error(): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -699,7 +714,7 @@ def test_get_policy_flattened_error(): @pytest.mark.asyncio async def test_get_policy_flattened_async(): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -716,14 +731,13 @@ async def test_get_policy_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_get_policy_flattened_error_async(): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -738,7 +752,7 @@ def test_update_policy( transport: str = "grpc", request_type=service.UpdatePolicyRequest ): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -753,23 +767,17 @@ def test_update_policy( description="description_value", global_policy_evaluation_mode=resources.Policy.GlobalPolicyEvaluationMode.ENABLE, ) - response = client.update_policy(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdatePolicyRequest() # Establish that the response is the type that we expect. - assert isinstance(response, resources.Policy) - assert response.name == "name_value" - assert response.description == "description_value" - assert ( response.global_policy_evaluation_mode == resources.Policy.GlobalPolicyEvaluationMode.ENABLE @@ -784,7 +792,7 @@ def test_update_policy_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -792,7 +800,6 @@ def test_update_policy_empty_call(): client.update_policy() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdatePolicyRequest() @@ -801,7 +808,7 @@ async def test_update_policy_async( transport: str = "grpc_asyncio", request_type=service.UpdatePolicyRequest ): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -818,22 +825,17 @@ async def test_update_policy_async( global_policy_evaluation_mode=resources.Policy.GlobalPolicyEvaluationMode.ENABLE, ) ) - response = await client.update_policy(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdatePolicyRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.Policy) - assert response.name == "name_value" - assert response.description == "description_value" - assert ( response.global_policy_evaluation_mode == resources.Policy.GlobalPolicyEvaluationMode.ENABLE @@ -847,18 +849,18 @@ async def test_update_policy_async_from_dict(): def test_update_policy_field_headers(): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UpdatePolicyRequest() + request.policy.name = "policy.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_policy), "__call__") as call: call.return_value = resources.Policy() - client.update_policy(request) # Establish that the underlying gRPC stub method was called. @@ -874,18 +876,18 @@ def test_update_policy_field_headers(): @pytest.mark.asyncio async def test_update_policy_field_headers_async(): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UpdatePolicyRequest() + request.policy.name = "policy.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_policy), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Policy()) - await client.update_policy(request) # Establish that the underlying gRPC stub method was called. @@ -900,43 +902,41 @@ async def test_update_policy_field_headers_async(): def test_update_policy_flattened(): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Policy() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.update_policy(policy_=resources.Policy(name="name_value"),) + client.update_policy(policy=resources.Policy(name="name_value"),) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - - assert args[0].policy_ == resources.Policy(name="name_value") + assert args[0].policy == resources.Policy(name="name_value") def test_update_policy_flattened_error(): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.update_policy( - service.UpdatePolicyRequest(), policy_=resources.Policy(name="name_value"), + service.UpdatePolicyRequest(), policy=resources.Policy(name="name_value"), ) @pytest.mark.asyncio async def test_update_policy_flattened_async(): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -948,28 +948,27 @@ async def test_update_policy_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.update_policy( - policy_=resources.Policy(name="name_value"), + policy=resources.Policy(name="name_value"), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - - assert args[0].policy_ == resources.Policy(name="name_value") + assert args[0].policy == resources.Policy(name="name_value") @pytest.mark.asyncio async def test_update_policy_flattened_error_async(): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.update_policy( - service.UpdatePolicyRequest(), policy_=resources.Policy(name="name_value"), + service.UpdatePolicyRequest(), policy=resources.Policy(name="name_value"), ) @@ -977,7 +976,7 @@ def test_create_attestor( transport: str = "grpc", request_type=service.CreateAttestorRequest ): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -994,21 +993,16 @@ def test_create_attestor( note_reference="note_reference_value" ), ) - response = client.create_attestor(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.CreateAttestorRequest() # Establish that the response is the type that we expect. - assert isinstance(response, resources.Attestor) - assert response.name == "name_value" - assert response.description == "description_value" @@ -1020,7 +1014,7 @@ def test_create_attestor_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1028,7 +1022,6 @@ def test_create_attestor_empty_call(): client.create_attestor() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.CreateAttestorRequest() @@ -1037,7 +1030,7 @@ async def test_create_attestor_async( transport: str = "grpc_asyncio", request_type=service.CreateAttestorRequest ): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1050,20 +1043,16 @@ async def test_create_attestor_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.Attestor(name="name_value", description="description_value",) ) - response = await client.create_attestor(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.CreateAttestorRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.Attestor) - assert response.name == "name_value" - assert response.description == "description_value" @@ -1074,18 +1063,18 @@ async def test_create_attestor_async_from_dict(): def test_create_attestor_field_headers(): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.CreateAttestorRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_attestor), "__call__") as call: call.return_value = resources.Attestor() - client.create_attestor(request) # Establish that the underlying gRPC stub method was called. @@ -1101,18 +1090,18 @@ def test_create_attestor_field_headers(): @pytest.mark.asyncio async def test_create_attestor_field_headers_async(): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.CreateAttestorRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_attestor), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Attestor()) - await client.create_attestor(request) # Establish that the underlying gRPC stub method was called. @@ -1127,14 +1116,13 @@ async def test_create_attestor_field_headers_async(): def test_create_attestor_flattened(): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_attestor), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Attestor() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_attestor( @@ -1147,17 +1135,14 @@ def test_create_attestor_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].attestor_id == "attestor_id_value" - assert args[0].attestor == resources.Attestor(name="name_value") def test_create_attestor_flattened_error(): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1174,7 +1159,7 @@ def test_create_attestor_flattened_error(): @pytest.mark.asyncio async def test_create_attestor_flattened_async(): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1195,18 +1180,15 @@ async def test_create_attestor_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].attestor_id == "attestor_id_value" - assert args[0].attestor == resources.Attestor(name="name_value") @pytest.mark.asyncio async def test_create_attestor_flattened_error_async(): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1222,7 +1204,7 @@ async def test_create_attestor_flattened_error_async(): def test_get_attestor(transport: str = "grpc", request_type=service.GetAttestorRequest): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1239,21 +1221,16 @@ def test_get_attestor(transport: str = "grpc", request_type=service.GetAttestorR note_reference="note_reference_value" ), ) - response = client.get_attestor(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.GetAttestorRequest() # Establish that the response is the type that we expect. - assert isinstance(response, resources.Attestor) - assert response.name == "name_value" - assert response.description == "description_value" @@ -1265,7 +1242,7 @@ def test_get_attestor_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1273,7 +1250,6 @@ def test_get_attestor_empty_call(): client.get_attestor() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.GetAttestorRequest() @@ -1282,7 +1258,7 @@ async def test_get_attestor_async( transport: str = "grpc_asyncio", request_type=service.GetAttestorRequest ): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1295,20 +1271,16 @@ async def test_get_attestor_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.Attestor(name="name_value", description="description_value",) ) - response = await client.get_attestor(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.GetAttestorRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.Attestor) - assert response.name == "name_value" - assert response.description == "description_value" @@ -1319,18 +1291,18 @@ async def test_get_attestor_async_from_dict(): def test_get_attestor_field_headers(): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetAttestorRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_attestor), "__call__") as call: call.return_value = resources.Attestor() - client.get_attestor(request) # Establish that the underlying gRPC stub method was called. @@ -1346,18 +1318,18 @@ def test_get_attestor_field_headers(): @pytest.mark.asyncio async def test_get_attestor_field_headers_async(): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.GetAttestorRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_attestor), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Attestor()) - await client.get_attestor(request) # Establish that the underlying gRPC stub method was called. @@ -1372,14 +1344,13 @@ async def test_get_attestor_field_headers_async(): def test_get_attestor_flattened(): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_attestor), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Attestor() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_attestor(name="name_value",) @@ -1388,13 +1359,12 @@ def test_get_attestor_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_attestor_flattened_error(): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1408,7 +1378,7 @@ def test_get_attestor_flattened_error(): @pytest.mark.asyncio async def test_get_attestor_flattened_async(): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1425,14 +1395,13 @@ async def test_get_attestor_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_get_attestor_flattened_error_async(): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1447,7 +1416,7 @@ def test_update_attestor( transport: str = "grpc", request_type=service.UpdateAttestorRequest ): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1464,21 +1433,16 @@ def test_update_attestor( note_reference="note_reference_value" ), ) - response = client.update_attestor(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdateAttestorRequest() # Establish that the response is the type that we expect. - assert isinstance(response, resources.Attestor) - assert response.name == "name_value" - assert response.description == "description_value" @@ -1490,7 +1454,7 @@ def test_update_attestor_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1498,7 +1462,6 @@ def test_update_attestor_empty_call(): client.update_attestor() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdateAttestorRequest() @@ -1507,7 +1470,7 @@ async def test_update_attestor_async( transport: str = "grpc_asyncio", request_type=service.UpdateAttestorRequest ): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1520,20 +1483,16 @@ async def test_update_attestor_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.Attestor(name="name_value", description="description_value",) ) - response = await client.update_attestor(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.UpdateAttestorRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.Attestor) - assert response.name == "name_value" - assert response.description == "description_value" @@ -1544,18 +1503,18 @@ async def test_update_attestor_async_from_dict(): def test_update_attestor_field_headers(): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UpdateAttestorRequest() + request.attestor.name = "attestor.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_attestor), "__call__") as call: call.return_value = resources.Attestor() - client.update_attestor(request) # Establish that the underlying gRPC stub method was called. @@ -1573,18 +1532,18 @@ def test_update_attestor_field_headers(): @pytest.mark.asyncio async def test_update_attestor_field_headers_async(): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.UpdateAttestorRequest() + request.attestor.name = "attestor.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_attestor), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Attestor()) - await client.update_attestor(request) # Establish that the underlying gRPC stub method was called. @@ -1601,14 +1560,13 @@ async def test_update_attestor_field_headers_async(): def test_update_attestor_flattened(): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_attestor), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Attestor() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.update_attestor(attestor=resources.Attestor(name="name_value"),) @@ -1617,13 +1575,12 @@ def test_update_attestor_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].attestor == resources.Attestor(name="name_value") def test_update_attestor_flattened_error(): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1638,7 +1595,7 @@ def test_update_attestor_flattened_error(): @pytest.mark.asyncio async def test_update_attestor_flattened_async(): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1657,14 +1614,13 @@ async def test_update_attestor_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].attestor == resources.Attestor(name="name_value") @pytest.mark.asyncio async def test_update_attestor_flattened_error_async(): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1680,7 +1636,7 @@ def test_list_attestors( transport: str = "grpc", request_type=service.ListAttestorsRequest ): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1693,19 +1649,15 @@ def test_list_attestors( call.return_value = service.ListAttestorsResponse( next_page_token="next_page_token_value", ) - response = client.list_attestors(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.ListAttestorsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListAttestorsPager) - assert response.next_page_token == "next_page_token_value" @@ -1717,7 +1669,7 @@ def test_list_attestors_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1725,7 +1677,6 @@ def test_list_attestors_empty_call(): client.list_attestors() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.ListAttestorsRequest() @@ -1734,7 +1685,7 @@ async def test_list_attestors_async( transport: str = "grpc_asyncio", request_type=service.ListAttestorsRequest ): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1747,18 +1698,15 @@ async def test_list_attestors_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service.ListAttestorsResponse(next_page_token="next_page_token_value",) ) - response = await client.list_attestors(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.ListAttestorsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListAttestorsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -1769,18 +1717,18 @@ async def test_list_attestors_async_from_dict(): def test_list_attestors_field_headers(): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ListAttestorsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_attestors), "__call__") as call: call.return_value = service.ListAttestorsResponse() - client.list_attestors(request) # Establish that the underlying gRPC stub method was called. @@ -1796,12 +1744,13 @@ def test_list_attestors_field_headers(): @pytest.mark.asyncio async def test_list_attestors_field_headers_async(): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.ListAttestorsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1809,7 +1758,6 @@ async def test_list_attestors_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service.ListAttestorsResponse() ) - await client.list_attestors(request) # Establish that the underlying gRPC stub method was called. @@ -1824,14 +1772,13 @@ async def test_list_attestors_field_headers_async(): def test_list_attestors_flattened(): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_attestors), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = service.ListAttestorsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_attestors(parent="parent_value",) @@ -1840,13 +1787,12 @@ def test_list_attestors_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_attestors_flattened_error(): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1860,7 +1806,7 @@ def test_list_attestors_flattened_error(): @pytest.mark.asyncio async def test_list_attestors_flattened_async(): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1879,14 +1825,13 @@ async def test_list_attestors_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @pytest.mark.asyncio async def test_list_attestors_flattened_error_async(): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1899,7 +1844,7 @@ async def test_list_attestors_flattened_error_async(): def test_list_attestors_pager(): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1939,7 +1884,7 @@ def test_list_attestors_pager(): def test_list_attestors_pages(): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1971,7 +1916,7 @@ def test_list_attestors_pages(): @pytest.mark.asyncio async def test_list_attestors_async_pager(): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2010,7 +1955,7 @@ async def test_list_attestors_async_pager(): @pytest.mark.asyncio async def test_list_attestors_async_pages(): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2047,7 +1992,7 @@ def test_delete_attestor( transport: str = "grpc", request_type=service.DeleteAttestorRequest ): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2058,13 +2003,11 @@ def test_delete_attestor( with mock.patch.object(type(client.transport.delete_attestor), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None - response = client.delete_attestor(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == service.DeleteAttestorRequest() # Establish that the response is the type that we expect. @@ -2079,7 +2022,7 @@ def test_delete_attestor_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2087,7 +2030,6 @@ def test_delete_attestor_empty_call(): client.delete_attestor() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == service.DeleteAttestorRequest() @@ -2096,7 +2038,7 @@ async def test_delete_attestor_async( transport: str = "grpc_asyncio", request_type=service.DeleteAttestorRequest ): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2107,13 +2049,11 @@ async def test_delete_attestor_async( with mock.patch.object(type(client.transport.delete_attestor), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_attestor(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == service.DeleteAttestorRequest() # Establish that the response is the type that we expect. @@ -2127,18 +2067,18 @@ async def test_delete_attestor_async_from_dict(): def test_delete_attestor_field_headers(): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.DeleteAttestorRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_attestor), "__call__") as call: call.return_value = None - client.delete_attestor(request) # Establish that the underlying gRPC stub method was called. @@ -2154,18 +2094,18 @@ def test_delete_attestor_field_headers(): @pytest.mark.asyncio async def test_delete_attestor_field_headers_async(): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = service.DeleteAttestorRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_attestor), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_attestor(request) # Establish that the underlying gRPC stub method was called. @@ -2180,14 +2120,13 @@ async def test_delete_attestor_field_headers_async(): def test_delete_attestor_flattened(): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_attestor), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.delete_attestor(name="name_value",) @@ -2196,13 +2135,12 @@ def test_delete_attestor_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_delete_attestor_flattened_error(): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -2216,7 +2154,7 @@ def test_delete_attestor_flattened_error(): @pytest.mark.asyncio async def test_delete_attestor_flattened_async(): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2233,14 +2171,13 @@ async def test_delete_attestor_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_delete_attestor_flattened_error_async(): client = BinauthzManagementServiceV1Beta1AsyncClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -2254,16 +2191,16 @@ async def test_delete_attestor_flattened_error_async(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.BinauthzManagementServiceV1Beta1GrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.BinauthzManagementServiceV1Beta1GrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = BinauthzManagementServiceV1Beta1Client( @@ -2273,7 +2210,7 @@ def test_credentials_transport_error(): # It is an error to provide scopes and a transport instance. transport = transports.BinauthzManagementServiceV1Beta1GrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = BinauthzManagementServiceV1Beta1Client( @@ -2284,7 +2221,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.BinauthzManagementServiceV1Beta1GrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) client = BinauthzManagementServiceV1Beta1Client(transport=transport) assert client.transport is transport @@ -2293,13 +2230,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.BinauthzManagementServiceV1Beta1GrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.BinauthzManagementServiceV1Beta1GrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -2314,8 +2251,8 @@ def test_transport_get_channel(): ) def test_transport_adc(transport_class): # Test default credentials are used if not provided. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class() adc.assert_called_once() @@ -2323,7 +2260,7 @@ def test_transport_adc(transport_class): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) assert isinstance( client.transport, transports.BinauthzManagementServiceV1Beta1GrpcTransport, @@ -2332,9 +2269,9 @@ def test_transport_grpc_default(): def test_binauthz_management_service_v1_beta1_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(exceptions.DuplicateCredentialArgs): + with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.BinauthzManagementServiceV1Beta1Transport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -2346,7 +2283,7 @@ def test_binauthz_management_service_v1_beta1_base_transport(): ) as Transport: Transport.return_value = None transport = transports.BinauthzManagementServiceV1Beta1Transport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -2365,15 +2302,37 @@ def test_binauthz_management_service_v1_beta1_base_transport(): getattr(transport, method)(request=object()) +@requires_google_auth_gte_1_25_0 def test_binauthz_management_service_v1_beta1_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( - auth, "load_credentials_from_file" + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.transports.BinauthzManagementServiceV1Beta1Transport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.BinauthzManagementServiceV1Beta1Transport( + credentials_file="credentials.json", quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_binauthz_management_service_v1_beta1_base_transport_with_credentials_file_old_google_auth(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True ) as load_creds, mock.patch( "google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.transports.BinauthzManagementServiceV1Beta1Transport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (credentials.AnonymousCredentials(), None) + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BinauthzManagementServiceV1Beta1Transport( credentials_file="credentials.json", quota_project_id="octopus", ) @@ -2386,19 +2345,33 @@ def test_binauthz_management_service_v1_beta1_base_transport_with_credentials_fi def test_binauthz_management_service_v1_beta1_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(auth, "default") as adc, mock.patch( + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( "google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.transports.BinauthzManagementServiceV1Beta1Transport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (credentials.AnonymousCredentials(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BinauthzManagementServiceV1Beta1Transport() adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_binauthz_management_service_v1_beta1_auth_adc(): # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + BinauthzManagementServiceV1Beta1Client() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_binauthz_management_service_v1_beta1_auth_adc_old_google_auth(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) BinauthzManagementServiceV1Beta1Client() adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), @@ -2406,20 +2379,169 @@ def test_binauthz_management_service_v1_beta1_auth_adc(): ) -def test_binauthz_management_service_v1_beta1_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [ + transports.BinauthzManagementServiceV1Beta1GrpcTransport, + transports.BinauthzManagementServiceV1Beta1GrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_binauthz_management_service_v1_beta1_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) - transports.BinauthzManagementServiceV1Beta1GrpcTransport( - host="squid.clam.whelk", quota_project_id="octopus" + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.BinauthzManagementServiceV1Beta1GrpcTransport, + transports.BinauthzManagementServiceV1Beta1GrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_binauthz_management_service_v1_beta1_transport_auth_adc_old_google_auth( + transport_class, +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus") adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), quota_project_id="octopus", ) +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.BinauthzManagementServiceV1Beta1GrpcTransport, grpc_helpers), + ( + transports.BinauthzManagementServiceV1Beta1GrpcAsyncIOTransport, + grpc_helpers_async, + ), + ], +) +@requires_api_core_gte_1_26_0 +def test_binauthz_management_service_v1_beta1_transport_create_channel( + transport_class, grpc_helpers +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "binaryauthorization.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="binaryauthorization.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.BinauthzManagementServiceV1Beta1GrpcTransport, grpc_helpers), + ( + transports.BinauthzManagementServiceV1Beta1GrpcAsyncIOTransport, + grpc_helpers_async, + ), + ], +) +@requires_api_core_lt_1_26_0 +def test_binauthz_management_service_v1_beta1_transport_create_channel_old_api_core( + transport_class, grpc_helpers +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus") + + create_channel.assert_called_with( + "binaryauthorization.googleapis.com", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.BinauthzManagementServiceV1Beta1GrpcTransport, grpc_helpers), + ( + transports.BinauthzManagementServiceV1Beta1GrpcAsyncIOTransport, + grpc_helpers_async, + ), + ], +) +@requires_api_core_lt_1_26_0 +def test_binauthz_management_service_v1_beta1_transport_create_channel_user_scopes( + transport_class, grpc_helpers +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "binaryauthorization.googleapis.com", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=["1", "2"], + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize( "transport_class", [ @@ -2430,7 +2552,7 @@ def test_binauthz_management_service_v1_beta1_transport_auth_adc(): def test_binauthz_management_service_v1_beta1_grpc_transport_client_cert_source_for_mtls( transport_class, ): - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -2469,7 +2591,7 @@ def test_binauthz_management_service_v1_beta1_grpc_transport_client_cert_source_ def test_binauthz_management_service_v1_beta1_host_no_port(): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="binaryauthorization.googleapis.com" ), @@ -2479,7 +2601,7 @@ def test_binauthz_management_service_v1_beta1_host_no_port(): def test_binauthz_management_service_v1_beta1_host_with_port(): client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="binaryauthorization.googleapis.com:8000" ), @@ -2535,9 +2657,9 @@ def test_binauthz_management_service_v1_beta1_transport_channel_mtls_with_client mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() with pytest.warns(DeprecationWarning): - with mock.patch.object(auth, "default") as adc: + with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) transport = transport_class( host="squid.clam.whelk", @@ -2616,7 +2738,6 @@ def test_binauthz_management_service_v1_beta1_transport_channel_mtls_with_adc( def test_attestor_path(): project = "squid" attestor = "clam" - expected = "projects/{project}/attestors/{attestor}".format( project=project, attestor=attestor, ) @@ -2638,7 +2759,6 @@ def test_parse_attestor_path(): def test_policy_path(): project = "oyster" - expected = "projects/{project}/policy".format(project=project,) actual = BinauthzManagementServiceV1Beta1Client.policy_path(project) assert expected == actual @@ -2657,7 +2777,6 @@ def test_parse_policy_path(): def test_common_billing_account_path(): billing_account = "cuttlefish" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -2684,7 +2803,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "winkle" - expected = "folders/{folder}".format(folder=folder,) actual = BinauthzManagementServiceV1Beta1Client.common_folder_path(folder) assert expected == actual @@ -2703,7 +2821,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "scallop" - expected = "organizations/{organization}".format(organization=organization,) actual = BinauthzManagementServiceV1Beta1Client.common_organization_path( organization @@ -2724,7 +2841,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "squid" - expected = "projects/{project}".format(project=project,) actual = BinauthzManagementServiceV1Beta1Client.common_project_path(project) assert expected == actual @@ -2744,7 +2860,6 @@ def test_parse_common_project_path(): def test_common_location_path(): project = "whelk" location = "octopus" - expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -2773,7 +2888,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.BinauthzManagementServiceV1Beta1Transport, "_prep_wrapped_messages" ) as prep: client = BinauthzManagementServiceV1Beta1Client( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2782,6 +2897,6 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = BinauthzManagementServiceV1Beta1Client.get_transport_class() transport = transport_class( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) From a965d86ba56b640a5245c38a53d003e7fe7f0489 Mon Sep 17 00:00:00 2001 From: yoshi-automation Date: Sat, 15 May 2021 04:51:02 +0000 Subject: [PATCH 08/12] feat: Publish Binary Authorization ContinuousValidationEvent proto. This is used in the new Continuous Validation feature: https://cloud.google.com/binary-authorization/docs/overview-cv Committer: @rbutoi PiperOrigin-RevId: 373173593 Source-Author: Google APIs Source-Date: Tue May 11 09:50:37 2021 -0700 Source-Repo: googleapis/googleapis Source-Sha: bceaea9f824a0d3600cd6a868ea457ac18980049 Source-Link: https://github.com/googleapis/googleapis/commit/bceaea9f824a0d3600cd6a868ea457ac18980049 --- google/cloud/binaryauthorization/__init__.py | 4 + .../binaryauthorization_v1beta1/__init__.py | 2 + .../types/__init__.py | 2 + .../types/continuous_validation_logging.py | 122 ++++++++++++++++++ synth.metadata | 5 +- 5 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 google/cloud/binaryauthorization_v1beta1/types/continuous_validation_logging.py diff --git a/google/cloud/binaryauthorization/__init__.py b/google/cloud/binaryauthorization/__init__.py index 80ed968..f054e4b 100644 --- a/google/cloud/binaryauthorization/__init__.py +++ b/google/cloud/binaryauthorization/__init__.py @@ -21,6 +21,9 @@ BinauthzManagementServiceV1Beta1AsyncClient, ) +from google.cloud.binaryauthorization_v1beta1.types.continuous_validation_logging import ( + ContinuousValidationEvent, +) from google.cloud.binaryauthorization_v1beta1.types.resources import AdmissionRule from google.cloud.binaryauthorization_v1beta1.types.resources import ( AdmissionWhitelistPattern, @@ -44,6 +47,7 @@ __all__ = ( "BinauthzManagementServiceV1Beta1Client", "BinauthzManagementServiceV1Beta1AsyncClient", + "ContinuousValidationEvent", "AdmissionRule", "AdmissionWhitelistPattern", "Attestor", diff --git a/google/cloud/binaryauthorization_v1beta1/__init__.py b/google/cloud/binaryauthorization_v1beta1/__init__.py index c775f65..a947c6c 100644 --- a/google/cloud/binaryauthorization_v1beta1/__init__.py +++ b/google/cloud/binaryauthorization_v1beta1/__init__.py @@ -21,6 +21,7 @@ BinauthzManagementServiceV1Beta1AsyncClient, ) +from .types.continuous_validation_logging import ContinuousValidationEvent from .types.resources import AdmissionRule from .types.resources import AdmissionWhitelistPattern from .types.resources import Attestor @@ -43,6 +44,7 @@ "Attestor", "AttestorPublicKey", "BinauthzManagementServiceV1Beta1Client", + "ContinuousValidationEvent", "CreateAttestorRequest", "DeleteAttestorRequest", "GetAttestorRequest", diff --git a/google/cloud/binaryauthorization_v1beta1/types/__init__.py b/google/cloud/binaryauthorization_v1beta1/types/__init__.py index 122112d..607c905 100644 --- a/google/cloud/binaryauthorization_v1beta1/types/__init__.py +++ b/google/cloud/binaryauthorization_v1beta1/types/__init__.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from .continuous_validation_logging import ContinuousValidationEvent from .resources import ( AdmissionRule, AdmissionWhitelistPattern, @@ -34,6 +35,7 @@ ) __all__ = ( + "ContinuousValidationEvent", "AdmissionRule", "AdmissionWhitelistPattern", "Attestor", diff --git a/google/cloud/binaryauthorization_v1beta1/types/continuous_validation_logging.py b/google/cloud/binaryauthorization_v1beta1/types/continuous_validation_logging.py new file mode 100644 index 0000000..4a1818a --- /dev/null +++ b/google/cloud/binaryauthorization_v1beta1/types/continuous_validation_logging.py @@ -0,0 +1,122 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import proto # type: ignore + +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.binaryauthorization.v1beta1", + manifest={"ContinuousValidationEvent",}, +) + + +class ContinuousValidationEvent(proto.Message): + r"""Represents an auditing event from Continuous Validation. + Attributes: + pod_event (google.cloud.binaryauthorization_v1beta1.types.ContinuousValidationEvent.ContinuousValidationPodEvent): + Pod event. + unsupported_policy_event (google.cloud.binaryauthorization_v1beta1.types.ContinuousValidationEvent.UnsupportedPolicyEvent): + Unsupported policy event. + """ + + class ContinuousValidationPodEvent(proto.Message): + r"""An auditing event for one Pod. + Attributes: + pod (str): + The name of the Pod. + deploy_time (google.protobuf.timestamp_pb2.Timestamp): + Deploy time of the Pod from k8s. + end_time (google.protobuf.timestamp_pb2.Timestamp): + Termination time of the Pod from k8s, or + nothing if still running. + verdict (google.cloud.binaryauthorization_v1beta1.types.ContinuousValidationEvent.ContinuousValidationPodEvent.PolicyConformanceVerdict): + Auditing verdict for this Pod. + images (Sequence[google.cloud.binaryauthorization_v1beta1.types.ContinuousValidationEvent.ContinuousValidationPodEvent.ImageDetails]): + List of images with auditing details. + """ + + class PolicyConformanceVerdict(proto.Enum): + r"""Audit time policy conformance verdict.""" + POLICY_CONFORMANCE_VERDICT_UNSPECIFIED = 0 + VIOLATES_POLICY = 1 + + class ImageDetails(proto.Message): + r"""Container image with auditing details. + Attributes: + image (str): + The name of the image. + result (google.cloud.binaryauthorization_v1beta1.types.ContinuousValidationEvent.ContinuousValidationPodEvent.ImageDetails.AuditResult): + The result of the audit for this image. + description (str): + Description of the above result. + """ + + class AuditResult(proto.Enum): + r"""Result of the audit.""" + AUDIT_RESULT_UNSPECIFIED = 0 + ALLOW = 1 + DENY = 2 + + image = proto.Field(proto.STRING, number=1,) + result = proto.Field( + proto.ENUM, + number=2, + enum="ContinuousValidationEvent.ContinuousValidationPodEvent.ImageDetails.AuditResult", + ) + description = proto.Field(proto.STRING, number=3,) + + pod = proto.Field(proto.STRING, number=1,) + deploy_time = proto.Field( + proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp, + ) + verdict = proto.Field( + proto.ENUM, + number=4, + enum="ContinuousValidationEvent.ContinuousValidationPodEvent.PolicyConformanceVerdict", + ) + images = proto.RepeatedField( + proto.MESSAGE, + number=5, + message="ContinuousValidationEvent.ContinuousValidationPodEvent.ImageDetails", + ) + + class UnsupportedPolicyEvent(proto.Message): + r"""An event describing that the project policy is unsupported by + CV. + + Attributes: + description (str): + A description of the unsupported policy. + """ + + description = proto.Field(proto.STRING, number=1,) + + pod_event = proto.Field( + proto.MESSAGE, + number=1, + oneof="event_type", + message=ContinuousValidationPodEvent, + ) + unsupported_policy_event = proto.Field( + proto.MESSAGE, number=2, oneof="event_type", message=UnsupportedPolicyEvent, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/synth.metadata b/synth.metadata index 227faa9..3c5532e 100644 --- a/synth.metadata +++ b/synth.metadata @@ -11,8 +11,8 @@ "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "83a7e1c8c2f7421ded45ed323eb1fda99ef5ea46", - "internalRef": "372197450" + "sha": "bceaea9f824a0d3600cd6a868ea457ac18980049", + "internalRef": "373173593" } } ], @@ -107,6 +107,7 @@ "google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py", "google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py", "google/cloud/binaryauthorization_v1beta1/types/__init__.py", + "google/cloud/binaryauthorization_v1beta1/types/continuous_validation_logging.py", "google/cloud/binaryauthorization_v1beta1/types/resources.py", "google/cloud/binaryauthorization_v1beta1/types/service.py", "mypy.ini", From 5a5b7824bcc8939520decb63202a0f2689a25ed8 Mon Sep 17 00:00:00 2001 From: yoshi-automation Date: Sat, 15 May 2021 04:52:09 +0000 Subject: [PATCH 09/12] chore: upgrade gapic-generator-python to 0.46.1 PiperOrigin-RevId: 373400747 Source-Author: Google APIs Source-Date: Wed May 12 10:34:35 2021 -0700 Source-Repo: googleapis/googleapis Source-Sha: 162641cfe5573c648df679a6dd30385650a08704 Source-Link: https://github.com/googleapis/googleapis/commit/162641cfe5573c648df679a6dd30385650a08704 --- examples/feature_fragments | 14 -------------- .../cloud/binaryauthorization_v1beta1/__init__.py | 1 + synth.metadata | 5 ++--- 3 files changed, 3 insertions(+), 17 deletions(-) delete mode 100644 examples/feature_fragments diff --git a/examples/feature_fragments b/examples/feature_fragments deleted file mode 100644 index 7d1b624..0000000 --- a/examples/feature_fragments +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - -} diff --git a/google/cloud/binaryauthorization_v1beta1/__init__.py b/google/cloud/binaryauthorization_v1beta1/__init__.py index a947c6c..200eb17 100644 --- a/google/cloud/binaryauthorization_v1beta1/__init__.py +++ b/google/cloud/binaryauthorization_v1beta1/__init__.py @@ -39,6 +39,7 @@ from .types.service import UpdatePolicyRequest __all__ = ( + "BinauthzManagementServiceV1Beta1AsyncClient", "AdmissionRule", "AdmissionWhitelistPattern", "Attestor", diff --git a/synth.metadata b/synth.metadata index 3c5532e..c65f13d 100644 --- a/synth.metadata +++ b/synth.metadata @@ -11,8 +11,8 @@ "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "bceaea9f824a0d3600cd6a868ea457ac18980049", - "internalRef": "373173593" + "sha": "162641cfe5573c648df679a6dd30385650a08704", + "internalRef": "373400747" } } ], @@ -91,7 +91,6 @@ "docs/binaryauthorization_v1beta1/types.rst", "docs/conf.py", "docs/multiprocessing.rst", - "examples/feature_fragments", "google/cloud/binaryauthorization/__init__.py", "google/cloud/binaryauthorization/py.typed", "google/cloud/binaryauthorization_v1beta1/__init__.py", From ad49af323e56e4f0e7e7ff067c9eabcca3a2dbff Mon Sep 17 00:00:00 2001 From: yoshi-automation Date: Sat, 15 May 2021 04:53:57 +0000 Subject: [PATCH 10/12] chore: upgrade gapic-generator-python to 0.46.3 PiperOrigin-RevId: 373649163 Source-Author: Google APIs Source-Date: Thu May 13 13:40:36 2021 -0700 Source-Repo: googleapis/googleapis Source-Sha: 7e1b14e6c7a9ab96d2db7e4a131981f162446d34 Source-Link: https://github.com/googleapis/googleapis/commit/7e1b14e6c7a9ab96d2db7e4a131981f162446d34 --- .../async_client.py | 27 +++++---- .../client.py | 56 ++++++++++--------- .../pagers.py | 2 +- synth.metadata | 4 +- ...st_binauthz_management_service_v1_beta1.py | 4 +- 5 files changed, 53 insertions(+), 40 deletions(-) diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py index b4b994a..6df73a1 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py @@ -98,7 +98,8 @@ class BinauthzManagementServiceV1Beta1AsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -113,7 +114,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -130,7 +131,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> BinauthzManagementServiceV1Beta1Transport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: BinauthzManagementServiceV1Beta1Transport: The transport used by the client instance. @@ -152,7 +153,7 @@ def __init__( client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the binauthz management service v1 beta1 client. + """Instantiates the binauthz management service v1 beta1 client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -264,7 +265,8 @@ async def get_policy( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -355,7 +357,8 @@ async def update_policy( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -548,7 +551,8 @@ async def get_attestor( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -637,7 +641,8 @@ async def update_attestor( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -726,7 +731,8 @@ async def list_attestors( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), @@ -811,7 +817,8 @@ async def delete_attestor( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, ), deadline=600.0, ), diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py index b2164e1..10521b1 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py @@ -65,7 +65,7 @@ class BinauthzManagementServiceV1Beta1ClientMeta(type): def get_transport_class( cls, label: str = None, ) -> Type[BinauthzManagementServiceV1Beta1Transport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -97,7 +97,8 @@ class BinauthzManagementServiceV1Beta1Client( @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -131,7 +132,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -148,7 +150,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -167,40 +169,41 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> BinauthzManagementServiceV1Beta1Transport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - BinauthzManagementServiceV1Beta1Transport: The transport used by the client instance. + BinauthzManagementServiceV1Beta1Transport: The transport used by the client + instance. """ return self._transport @staticmethod def attestor_path(project: str, attestor: str,) -> str: - """Return a fully-qualified attestor string.""" + """Returns a fully-qualified attestor string.""" return "projects/{project}/attestors/{attestor}".format( project=project, attestor=attestor, ) @staticmethod def parse_attestor_path(path: str) -> Dict[str, str]: - """Parse a attestor path into its component segments.""" + """Parses a attestor path into its component segments.""" m = re.match(r"^projects/(?P.+?)/attestors/(?P.+?)$", path) return m.groupdict() if m else {} @staticmethod def policy_path(project: str,) -> str: - """Return a fully-qualified policy string.""" + """Returns a fully-qualified policy string.""" return "projects/{project}/policy".format(project=project,) @staticmethod def parse_policy_path(path: str) -> Dict[str, str]: - """Parse a policy path into its component segments.""" + """Parses a policy path into its component segments.""" m = re.match(r"^projects/(?P.+?)/policy$", path) return m.groupdict() if m else {} @staticmethod def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -213,7 +216,7 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: @staticmethod def common_folder_path(folder: str,) -> str: - """Return a fully-qualified folder string.""" + """Returns a fully-qualified folder string.""" return "folders/{folder}".format(folder=folder,) @staticmethod @@ -224,7 +227,7 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: @staticmethod def common_organization_path(organization: str,) -> str: - """Return a fully-qualified organization string.""" + """Returns a fully-qualified organization string.""" return "organizations/{organization}".format(organization=organization,) @staticmethod @@ -235,7 +238,7 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: @staticmethod def common_project_path(project: str,) -> str: - """Return a fully-qualified project string.""" + """Returns a fully-qualified project string.""" return "projects/{project}".format(project=project,) @staticmethod @@ -246,7 +249,7 @@ def parse_common_project_path(path: str) -> Dict[str, str]: @staticmethod def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -265,7 +268,7 @@ def __init__( client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the binauthz management service v1 beta1 client. + """Instantiates the binauthz management service v1 beta1 client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -320,9 +323,10 @@ def __init__( client_cert_source_func = client_options.client_cert_source else: is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() if is_mtls else None - ) + if is_mtls: + client_cert_source_func = mtls.default_client_cert_source() + else: + client_cert_source_func = None # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -334,12 +338,14 @@ def __init__( elif use_mtls_env == "always": api_endpoint = self.DEFAULT_MTLS_ENDPOINT elif use_mtls_env == "auto": - api_endpoint = ( - self.DEFAULT_MTLS_ENDPOINT if is_mtls else self.DEFAULT_ENDPOINT - ) + if is_mtls: + api_endpoint = self.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = self.DEFAULT_ENDPOINT else: raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted values: never, auto, always" + "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " + "values: never, auto, always" ) # Save or instantiate the transport. @@ -354,8 +360,8 @@ def __init__( ) if client_options.scopes: raise ValueError( - "When providing a transport instance, " - "provide its scopes directly." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: diff --git a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/pagers.py b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/pagers.py index 9aecf4b..3a010c6 100644 --- a/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/pagers.py +++ b/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/pagers.py @@ -116,7 +116,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and diff --git a/synth.metadata b/synth.metadata index c65f13d..602a80c 100644 --- a/synth.metadata +++ b/synth.metadata @@ -11,8 +11,8 @@ "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "162641cfe5573c648df679a6dd30385650a08704", - "internalRef": "373400747" + "sha": "7e1b14e6c7a9ab96d2db7e4a131981f162446d34", + "internalRef": "373649163" } } ], diff --git a/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py b/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py index 3873031..054f861 100644 --- a/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py +++ b/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py @@ -2489,7 +2489,7 @@ def test_binauthz_management_service_v1_beta1_transport_create_channel_old_api_c transport_class(quota_project_id="octopus") create_channel.assert_called_with( - "binaryauthorization.googleapis.com", + "binaryauthorization.googleapis.com:443", credentials=creds, credentials_file=None, quota_project_id="octopus", @@ -2529,7 +2529,7 @@ def test_binauthz_management_service_v1_beta1_transport_create_channel_user_scop transport_class(quota_project_id="octopus", scopes=["1", "2"]) create_channel.assert_called_with( - "binaryauthorization.googleapis.com", + "binaryauthorization.googleapis.com:443", credentials=creds, credentials_file=None, quota_project_id="octopus", From 886034f779601b48d2ee3820ac51635667dac2dc Mon Sep 17 00:00:00 2001 From: Dina Graves Portman Date: Mon, 17 May 2021 16:15:51 -0700 Subject: [PATCH 11/12] Delete synth.metadata Removed in previous PR --- synth.metadata | 131 ------------------------------------------------- 1 file changed, 131 deletions(-) delete mode 100644 synth.metadata diff --git a/synth.metadata b/synth.metadata deleted file mode 100644 index 602a80c..0000000 --- a/synth.metadata +++ /dev/null @@ -1,131 +0,0 @@ -{ - "sources": [ - { - "git": { - "name": ".", - "remote": "https://github.com/googleapis/python-binary-authorization.git", - "sha": "996f5010afd4372d625a9accc57647bac46770a8" - } - }, - { - "git": { - "name": "googleapis", - "remote": "https://github.com/googleapis/googleapis.git", - "sha": "7e1b14e6c7a9ab96d2db7e4a131981f162446d34", - "internalRef": "373649163" - } - } - ], - "destinations": [ - { - "client": { - "source": "googleapis", - "apiName": "binaryauthorization", - "apiVersion": "v1beta1", - "language": "python", - "generator": "bazel" - } - } - ], - "generatedFiles": [ - ".coveragerc", - ".flake8", - ".github/CONTRIBUTING.md", - ".github/ISSUE_TEMPLATE/bug_report.md", - ".github/ISSUE_TEMPLATE/feature_request.md", - ".github/ISSUE_TEMPLATE/support_request.md", - ".github/PULL_REQUEST_TEMPLATE.md", - ".github/header-checker-lint.yml", - ".github/release-please.yml", - ".github/snippet-bot.yml", - ".gitignore", - ".kokoro/build.sh", - ".kokoro/continuous/common.cfg", - ".kokoro/continuous/continuous.cfg", - ".kokoro/docker/docs/Dockerfile", - ".kokoro/docker/docs/fetch_gpg_keys.sh", - ".kokoro/docs/common.cfg", - ".kokoro/docs/docs-presubmit.cfg", - ".kokoro/docs/docs.cfg", - ".kokoro/populate-secrets.sh", - ".kokoro/presubmit/common.cfg", - ".kokoro/presubmit/presubmit.cfg", - ".kokoro/publish-docs.sh", - ".kokoro/release.sh", - ".kokoro/release/common.cfg", - ".kokoro/release/release.cfg", - ".kokoro/samples/lint/common.cfg", - ".kokoro/samples/lint/continuous.cfg", - ".kokoro/samples/lint/periodic.cfg", - ".kokoro/samples/lint/presubmit.cfg", - ".kokoro/samples/python3.6/common.cfg", - ".kokoro/samples/python3.6/continuous.cfg", - ".kokoro/samples/python3.6/periodic-head.cfg", - ".kokoro/samples/python3.6/periodic.cfg", - ".kokoro/samples/python3.6/presubmit.cfg", - ".kokoro/samples/python3.7/common.cfg", - ".kokoro/samples/python3.7/continuous.cfg", - ".kokoro/samples/python3.7/periodic-head.cfg", - ".kokoro/samples/python3.7/periodic.cfg", - ".kokoro/samples/python3.7/presubmit.cfg", - ".kokoro/samples/python3.8/common.cfg", - ".kokoro/samples/python3.8/continuous.cfg", - ".kokoro/samples/python3.8/periodic-head.cfg", - ".kokoro/samples/python3.8/periodic.cfg", - ".kokoro/samples/python3.8/presubmit.cfg", - ".kokoro/test-samples-against-head.sh", - ".kokoro/test-samples-impl.sh", - ".kokoro/test-samples.sh", - ".kokoro/trampoline.sh", - ".kokoro/trampoline_v2.sh", - ".pre-commit-config.yaml", - ".trampolinerc", - "CODE_OF_CONDUCT.md", - "CONTRIBUTING.rst", - "LICENSE", - "MANIFEST.in", - "docs/_static/custom.css", - "docs/_templates/layout.html", - "docs/binaryauthorization_v1beta1/binauthz_management_service_v1_beta1.rst", - "docs/binaryauthorization_v1beta1/services.rst", - "docs/binaryauthorization_v1beta1/types.rst", - "docs/conf.py", - "docs/multiprocessing.rst", - "google/cloud/binaryauthorization/__init__.py", - "google/cloud/binaryauthorization/py.typed", - "google/cloud/binaryauthorization_v1beta1/__init__.py", - "google/cloud/binaryauthorization_v1beta1/gapic_metadata.json", - "google/cloud/binaryauthorization_v1beta1/py.typed", - "google/cloud/binaryauthorization_v1beta1/services/__init__.py", - "google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/__init__.py", - "google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py", - "google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py", - "google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/pagers.py", - "google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/__init__.py", - "google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/base.py", - "google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py", - "google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py", - "google/cloud/binaryauthorization_v1beta1/types/__init__.py", - "google/cloud/binaryauthorization_v1beta1/types/continuous_validation_logging.py", - "google/cloud/binaryauthorization_v1beta1/types/resources.py", - "google/cloud/binaryauthorization_v1beta1/types/service.py", - "mypy.ini", - "noxfile.py", - "renovate.json", - "scripts/decrypt-secrets.sh", - "scripts/fixup_binaryauthorization_v1beta1_keywords.py", - "scripts/readme-gen/readme_gen.py", - "scripts/readme-gen/templates/README.tmpl.rst", - "scripts/readme-gen/templates/auth.tmpl.rst", - "scripts/readme-gen/templates/auth_api_key.tmpl.rst", - "scripts/readme-gen/templates/install_deps.tmpl.rst", - "scripts/readme-gen/templates/install_portaudio.tmpl.rst", - "setup.cfg", - "testing/.gitignore", - "tests/__init__.py", - "tests/unit/__init__.py", - "tests/unit/gapic/__init__.py", - "tests/unit/gapic/binaryauthorization_v1beta1/__init__.py", - "tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py" - ] -} \ No newline at end of file From 780ca3383d340dd6d7aa372c1d3697497515c858 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Mon, 17 May 2021 23:18:23 +0000 Subject: [PATCH 12/12] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4f00c7c..1bbd787 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -26,6 +26,6 @@ repos: hooks: - id: black - repo: https://gitlab.com/pycqa/flake8 - rev: 3.9.2 + rev: 3.9.1 hooks: - id: flake8