diff --git a/packages/google-cloud-binary-authorization/.coveragerc b/packages/google-cloud-binary-authorization/.coveragerc index 5ff8242fc110..95c4014b1f4c 100644 --- a/packages/google-cloud-binary-authorization/.coveragerc +++ b/packages/google-cloud-binary-authorization/.coveragerc @@ -2,7 +2,6 @@ branch = True [report] -fail_under = 100 show_missing = True omit = google/cloud/binaryauthorization/__init__.py diff --git a/packages/google-cloud-binary-authorization/docs/binaryauthorization_v1beta1/binauthz_management_service_v1_beta1.rst b/packages/google-cloud-binary-authorization/docs/binaryauthorization_v1beta1/binauthz_management_service_v1_beta1.rst index 5868c89df86c..22016d07f1e7 100644 --- a/packages/google-cloud-binary-authorization/docs/binaryauthorization_v1beta1/binauthz_management_service_v1_beta1.rst +++ b/packages/google-cloud-binary-authorization/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/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization/__init__.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization/__init__.py index f082bea004b8..f054e4b93082 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization/__init__.py +++ b/packages/google-cloud-binary-authorization/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,11 +14,15 @@ # 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.continuous_validation_logging import ( + ContinuousValidationEvent, ) from google.cloud.binaryauthorization_v1beta1.types.resources import AdmissionRule from google.cloud.binaryauthorization_v1beta1.types.resources import ( @@ -42,21 +45,22 @@ from google.cloud.binaryauthorization_v1beta1.types.service import UpdatePolicyRequest __all__ = ( + "BinauthzManagementServiceV1Beta1Client", + "BinauthzManagementServiceV1Beta1AsyncClient", + "ContinuousValidationEvent", "AdmissionRule", "AdmissionWhitelistPattern", "Attestor", "AttestorPublicKey", - "BinauthzManagementServiceV1Beta1AsyncClient", - "BinauthzManagementServiceV1Beta1Client", + "PkixPublicKey", + "Policy", + "UserOwnedDrydockNote", "CreateAttestorRequest", "DeleteAttestorRequest", "GetAttestorRequest", "GetPolicyRequest", "ListAttestorsRequest", "ListAttestorsResponse", - "PkixPublicKey", - "Policy", "UpdateAttestorRequest", "UpdatePolicyRequest", - "UserOwnedDrydockNote", ) diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/__init__.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/__init__.py index 5f14b9c0c182..200eb1726e72 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/__init__.py +++ b/packages/google-cloud-binary-authorization/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,11 @@ from .services.binauthz_management_service_v1_beta1 import ( BinauthzManagementServiceV1Beta1Client, ) +from .services.binauthz_management_service_v1_beta1 import ( + BinauthzManagementServiceV1Beta1AsyncClient, +) + +from .types.continuous_validation_logging import ContinuousValidationEvent from .types.resources import AdmissionRule from .types.resources import AdmissionWhitelistPattern from .types.resources import Attestor @@ -34,12 +38,14 @@ from .types.service import UpdateAttestorRequest from .types.service import UpdatePolicyRequest - __all__ = ( + "BinauthzManagementServiceV1Beta1AsyncClient", "AdmissionRule", "AdmissionWhitelistPattern", "Attestor", "AttestorPublicKey", + "BinauthzManagementServiceV1Beta1Client", + "ContinuousValidationEvent", "CreateAttestorRequest", "DeleteAttestorRequest", "GetAttestorRequest", @@ -51,5 +57,4 @@ "UpdateAttestorRequest", "UpdatePolicyRequest", "UserOwnedDrydockNote", - "BinauthzManagementServiceV1Beta1Client", ) diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/gapic_metadata.json b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/gapic_metadata.json new file mode 100644 index 000000000000..8e5695567846 --- /dev/null +++ b/packages/google-cloud-binary-authorization/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/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/__init__.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/__init__.py index 42ffdf2bc43d..4de65971c238 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/__init__.py +++ b/packages/google-cloud-binary-authorization/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/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/__init__.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/__init__.py index f832d0c07475..e13361500f1f 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/__init__.py +++ b/packages/google-cloud-binary-authorization/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/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py index 8876be6b331d..6df73a125610 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py +++ b/packages/google-cloud-binary-authorization/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 ) @@ -106,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. @@ -121,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 @@ -138,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. @@ -153,14 +146,14 @@ def transport(self) -> BinauthzManagementServiceV1Beta1Transport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[ str, BinauthzManagementServiceV1Beta1Transport ] = "grpc_asyncio", 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 @@ -192,7 +185,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 +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 @@ -275,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, ), @@ -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 @@ -368,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, ), @@ -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: @@ -524,7 +512,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 +539,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 @@ -565,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, ), @@ -615,7 +602,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 +629,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 @@ -656,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, ), @@ -704,7 +690,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 +719,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 @@ -747,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, ), @@ -800,7 +785,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 +805,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 @@ -834,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/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py index aac65a5fb6ae..10521b125e7b 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py +++ b/packages/google-cloud-binary-authorization/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, @@ -68,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 @@ -100,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: @@ -134,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. @@ -151,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 @@ -170,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, ) @@ -216,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 @@ -227,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 @@ -238,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 @@ -249,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, ) @@ -263,12 +263,12 @@ 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, ) -> 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 @@ -323,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: @@ -337,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. @@ -357,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: @@ -408,7 +411,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 +439,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 @@ -493,7 +493,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 +521,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 @@ -598,7 +595,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 +624,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 +676,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 +705,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 +756,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 +785,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 +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 @@ -934,7 +919,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 +941,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/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/pagers.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/pagers.py index 42c46596303f..3a010c6e1dc3 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/pagers.py +++ b/packages/google-cloud-binary-authorization/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, @@ -118,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/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/__init__.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/__init__.py index 78aef3f2fade..bf3c24d658eb 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/__init__.py +++ b/packages/google-cloud-binary-authorization/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/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/base.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/base.py index 9bc0a2225b57..6a3d84ac337d 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/base.py +++ b/packages/google-cloud-binary-authorization/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/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py index e2a2f5b25aa0..1c0b0daa31a6 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py +++ b/packages/google-cloud-binary-authorization/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/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py index 4b621dac7f1c..3b11c3256f38 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py +++ b/packages/google-cloud-binary-authorization/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/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/types/__init__.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/types/__init__.py index b4424d494294..607c9053a363 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/types/__init__.py +++ b/packages/google-cloud-binary-authorization/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,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, @@ -36,6 +35,7 @@ ) __all__ = ( + "ContinuousValidationEvent", "AdmissionRule", "AdmissionWhitelistPattern", "Attestor", diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/types/continuous_validation_logging.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/types/continuous_validation_logging.py new file mode 100644 index 000000000000..4a1818a4bea2 --- /dev/null +++ b/packages/google-cloud-binary-authorization/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/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/types/resources.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/types/resources.py index 7866476a4655..a04d6817f8ab 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/types/resources.py +++ b/packages/google-cloud-binary-authorization/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/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/types/service.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/types/service.py index d2193415edb3..ccf4e94964cd 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/types/service.py +++ b/packages/google-cloud-binary-authorization/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/packages/google-cloud-binary-authorization/scripts/fixup_binaryauthorization_v1beta1_keywords.py b/packages/google-cloud-binary-authorization/scripts/fixup_binaryauthorization_v1beta1_keywords.py index 6d42b25cf959..95b795be95b6 100644 --- a/packages/google-cloud-binary-authorization/scripts/fixup_binaryauthorization_v1beta1_keywords.py +++ b/packages/google-cloud-binary-authorization/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/packages/google-cloud-binary-authorization/tests/__init__.py b/packages/google-cloud-binary-authorization/tests/__init__.py new file mode 100644 index 000000000000..4de65971c238 --- /dev/null +++ b/packages/google-cloud-binary-authorization/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/packages/google-cloud-binary-authorization/tests/unit/__init__.py b/packages/google-cloud-binary-authorization/tests/unit/__init__.py new file mode 100644 index 000000000000..4de65971c238 --- /dev/null +++ b/packages/google-cloud-binary-authorization/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/packages/google-cloud-binary-authorization/tests/unit/gapic/__init__.py b/packages/google-cloud-binary-authorization/tests/unit/gapic/__init__.py new file mode 100644 index 000000000000..4de65971c238 --- /dev/null +++ b/packages/google-cloud-binary-authorization/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/packages/google-cloud-binary-authorization/tests/unit/gapic/binaryauthorization_v1beta1/__init__.py b/packages/google-cloud-binary-authorization/tests/unit/gapic/binaryauthorization_v1beta1/__init__.py index 42ffdf2bc43d..4de65971c238 100644 --- a/packages/google-cloud-binary-authorization/tests/unit/gapic/binaryauthorization_v1beta1/__init__.py +++ b/packages/google-cloud-binary-authorization/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/packages/google-cloud-binary-authorization/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py b/packages/google-cloud-binary-authorization/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py index 0c189684d21b..054f861e1f62 100644 --- a/packages/google-cloud-binary-authorization/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py +++ b/packages/google-cloud-binary-authorization/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,14 +902,13 @@ 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"),) @@ -916,13 +917,12 @@ 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") 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 @@ -936,7 +936,7 @@ def test_update_policy_flattened_error(): @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. @@ -955,14 +955,13 @@ 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") @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 @@ -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:443", + 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:443", + 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)