diff --git a/packages/google-cloud-org-policy/google/cloud/orgpolicy/__init__.py b/packages/google-cloud-org-policy/google/cloud/orgpolicy/__init__.py index 1d74e6ab7993..0a372b29cab0 100644 --- a/packages/google-cloud-org-policy/google/cloud/orgpolicy/__init__.py +++ b/packages/google-cloud-org-policy/google/cloud/orgpolicy/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/__init__.py b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/__init__.py index 65811eba810e..44109097ba61 100644 --- a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/__init__.py +++ b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/__init__.py b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/__init__.py index 89a37dc92c5a..8f6cf068242c 100644 --- a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/__init__.py +++ b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/__init__.py b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/__init__.py index f69b7a40026a..3683846e2897 100644 --- a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/__init__.py +++ b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/async_client.py b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/async_client.py index 5a5cda1b6446..627080278acd 100644 --- a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/async_client.py +++ b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -38,9 +38,9 @@ from google.oauth2 import service_account # type: ignore try: - OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault] + OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None] except AttributeError: # pragma: NO COVER - OptionalRetry = Union[retries.AsyncRetry, object] # type: ignore + OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore from google.cloud.orgpolicy_v2.services.org_policy import pagers from google.cloud.orgpolicy_v2.types import constraint @@ -78,8 +78,12 @@ class OrgPolicyAsyncClient: _client: OrgPolicyClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = OrgPolicyClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = OrgPolicyClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = OrgPolicyClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = OrgPolicyClient._DEFAULT_UNIVERSE constraint_path = staticmethod(OrgPolicyClient.constraint_path) parse_constraint_path = staticmethod(OrgPolicyClient.parse_constraint_path) @@ -186,6 +190,25 @@ def transport(self) -> OrgPolicyTransport: """ return self._client.transport + @property + def api_endpoint(self): + """Return the API endpoint used by the client instance. + + Returns: + str: The API endpoint used by the client instance. + """ + return self._client._api_endpoint + + @property + def universe_domain(self) -> str: + """Return the universe domain used by the client instance. + + Returns: + str: The universe domain used + by the client instance. + """ + return self._client._universe_domain + get_transport_class = functools.partial( type(OrgPolicyClient).get_transport_class, type(OrgPolicyClient) ) @@ -198,7 +221,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the org policy client. + """Instantiates the org policy async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -209,23 +232,38 @@ def __init__( transport (Union[str, ~.OrgPolicyTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (ClientOptions): Custom options for the client. It - won't take effect if a ``transport`` instance is provided. - (1) The ``api_endpoint`` property can be used to override the - default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT - environment variable can also be used to override the endpoint: + client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): + Custom options for the client. + + 1. The ``api_endpoint`` property can be used to override the + default endpoint provided by the client when ``transport`` is + not explicitly provided. Only if this property is not set and + ``transport`` was not explicitly provided, the endpoint is + determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment + variable, which have one of the following values: "always" (always use the default mTLS endpoint), "never" (always - use the default regular endpoint) and "auto" (auto switch to the - default mTLS endpoint if client certificate is present, this is - the default value). However, the ``api_endpoint`` property takes - precedence if provided. - (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + use the default regular endpoint) and "auto" (auto-switch to the + default mTLS endpoint if client certificate is present; this is + the default value). + + 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable is "true", then the ``client_cert_source`` property can be used - to provide client certificate for mutual TLS transport. If + to provide a client certificate for mTLS transport. If not provided, the default SSL client certificate will be used if present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not set, no client certificate will be used. + 3. The ``universe_domain`` property can be used to override the + default "googleapis.com" universe. Note that ``api_endpoint`` + property still takes precedence; and ``universe_domain`` is + currently not supported for mTLS. + + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. @@ -350,6 +388,9 @@ async def sample_list_constraints(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -486,6 +527,9 @@ async def sample_list_policies(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -614,6 +658,9 @@ async def sample_get_policy(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -735,6 +782,9 @@ async def sample_get_effective_policy(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -869,6 +919,9 @@ async def sample_create_policy(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -992,6 +1045,9 @@ async def sample_update_policy(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1101,6 +1157,9 @@ async def sample_delete_policy(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. await rpc( request, @@ -1233,6 +1292,9 @@ async def sample_create_custom_constraint(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1356,6 +1418,9 @@ async def sample_update_custom_constraint(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1479,6 +1544,9 @@ async def sample_get_custom_constraint(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1602,6 +1670,9 @@ async def sample_list_custom_constraints(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1719,6 +1790,9 @@ async def sample_delete_custom_constraint(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. await rpc( request, diff --git a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/client.py b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/client.py index fbb0b6135de0..8eacc28c3f07 100644 --- a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/client.py +++ b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.cloud.orgpolicy_v2 import gapic_version as package_version @@ -42,9 +43,9 @@ from google.oauth2 import service_account # type: ignore try: - OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] except AttributeError: # pragma: NO COVER - OptionalRetry = Union[retries.Retry, object] # type: ignore + OptionalRetry = Union[retries.Retry, object, None] # type: ignore from google.cloud.orgpolicy_v2.services.org_policy import pagers from google.cloud.orgpolicy_v2.types import constraint @@ -146,11 +147,15 @@ def _get_default_mtls_endpoint(api_endpoint): return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = "orgpolicy.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "orgpolicy.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials @@ -337,7 +342,7 @@ def parse_common_location_path(path: str) -> Dict[str, str]: def get_mtls_endpoint_and_cert_source( cls, client_options: Optional[client_options_lib.ClientOptions] = None ): - """Return the API endpoint and client cert source for mutual TLS. + """Deprecated. Return the API endpoint and client cert source for mutual TLS. The client cert source is determined in the following order: (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the @@ -367,6 +372,11 @@ def get_mtls_endpoint_and_cert_source( Raises: google.auth.exceptions.MutualTLSChannelError: If any errors happen. """ + + warnings.warn( + "get_mtls_endpoint_and_cert_source is deprecated. Use the api_endpoint property instead.", + DeprecationWarning, + ) if client_options is None: client_options = client_options_lib.ClientOptions() use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") @@ -400,6 +410,178 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert == "true", use_mtls_endpoint, universe_domain_env + + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod + def _get_api_endpoint( + api_override, client_cert_source, universe_domain, use_mtls_endpoint + ): + """Return the API endpoint used by the client. + + Args: + api_override (str): The API endpoint override. If specified, this is always + the return value of this function and the other arguments are not used. + client_cert_source (bytes): The client certificate source used by the client. + universe_domain (str): The universe domain used by the client. + use_mtls_endpoint (str): How to use the mTLS endpoint, which depends also on the other parameters. + Possible values are "always", "auto", or "never". + + Returns: + str: The API endpoint to be used by the client. + """ + if api_override is not None: + api_endpoint = api_override + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + _default_universe = OrgPolicyClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = OrgPolicyClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = OrgPolicyClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=universe_domain + ) + return api_endpoint + + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = OrgPolicyClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain + + @staticmethod + def _compare_universes( + client_universe: str, credentials: ga_credentials.Credentials + ) -> bool: + """Returns True iff the universe domains used by the client and credentials match. + + Args: + client_universe (str): The universe domain configured via the client options. + credentials (ga_credentials.Credentials): The credentials being used in the client. + + Returns: + bool: True iff client_universe matches the universe in credentials. + + Raises: + ValueError: when client_universe does not match the universe in credentials. + """ + + default_universe = OrgPolicyClient._DEFAULT_UNIVERSE + credentials_universe = getattr(credentials, "universe_domain", default_universe) + + if client_universe != credentials_universe: + raise ValueError( + "The configured universe domain " + f"({client_universe}) does not match the universe domain " + f"found in the credentials ({credentials_universe}). " + "If you haven't configured the universe domain explicitly, " + f"`{default_universe}` is the default." + ) + return True + + def _validate_universe_domain(self): + """Validates client's and credentials' universe domains are consistent. + + Returns: + bool: True iff the configured universe domain is valid. + + Raises: + ValueError: If the configured universe domain is not valid. + """ + self._is_universe_domain_valid = ( + self._is_universe_domain_valid + or OrgPolicyClient._compare_universes( + self.universe_domain, self.transport._credentials + ) + ) + return self._is_universe_domain_valid + + @property + def api_endpoint(self): + """Return the API endpoint used by the client instance. + + Returns: + str: The API endpoint used by the client instance. + """ + return self._api_endpoint + + @property + def universe_domain(self) -> str: + """Return the universe domain used by the client instance. + + Returns: + str: The universe domain used by the client instance. + """ + return self._universe_domain + def __init__( self, *, @@ -419,22 +601,32 @@ def __init__( transport (Union[str, OrgPolicyTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): Custom options for the - client. It won't take effect if a ``transport`` instance is provided. - (1) The ``api_endpoint`` property can be used to override the - default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT - environment variable can also be used to override the endpoint: + client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): + Custom options for the client. + + 1. The ``api_endpoint`` property can be used to override the + default endpoint provided by the client when ``transport`` is + not explicitly provided. Only if this property is not set and + ``transport`` was not explicitly provided, the endpoint is + determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment + variable, which have one of the following values: "always" (always use the default mTLS endpoint), "never" (always - use the default regular endpoint) and "auto" (auto switch to the - default mTLS endpoint if client certificate is present, this is - the default value). However, the ``api_endpoint`` property takes - precedence if provided. - (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + use the default regular endpoint) and "auto" (auto-switch to the + default mTLS endpoint if client certificate is present; this is + the default value). + + 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable is "true", then the ``client_cert_source`` property can be used - to provide client certificate for mutual TLS transport. If + to provide a client certificate for mTLS transport. If not provided, the default SSL client certificate will be used if present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not set, no client certificate will be used. + + 3. The ``universe_domain`` property can be used to override the + default "googleapis.com" universe. Note that the ``api_endpoint`` + property still takes precedence; and ``universe_domain`` is + currently not supported for mTLS. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): The client info used to send a user-agent string along with API requests. If ``None``, then default info will be used. @@ -445,17 +637,34 @@ def __init__( google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport creation failed for any reason. """ - if isinstance(client_options, dict): - client_options = client_options_lib.from_dict(client_options) - if client_options is None: - client_options = client_options_lib.ClientOptions() - client_options = cast(client_options_lib.ClientOptions, client_options) + self._client_options = client_options + if isinstance(self._client_options, dict): + self._client_options = client_options_lib.from_dict(self._client_options) + if self._client_options is None: + self._client_options = client_options_lib.ClientOptions() + self._client_options = cast( + client_options_lib.ClientOptions, self._client_options + ) + + universe_domain_opt = getattr(self._client_options, "universe_domain", None) - api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( - client_options + ( + self._use_client_cert, + self._use_mtls_endpoint, + self._universe_domain_env, + ) = OrgPolicyClient._read_environment_variables() + self._client_cert_source = OrgPolicyClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = OrgPolicyClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env ) + self._api_endpoint = None # updated below, depending on `transport` - api_key_value = getattr(client_options, "api_key", None) + # Initialize the universe domain validation. + self._is_universe_domain_valid = False + + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( "client_options.api_key and credentials are mutually exclusive" @@ -464,20 +673,30 @@ def __init__( # Save or instantiate the transport. # Ordinarily, we provide the transport, but allowing a custom transport # instance provides an extensibility point for unusual situations. - if isinstance(transport, OrgPolicyTransport): + transport_provided = isinstance(transport, OrgPolicyTransport) + if transport_provided: # transport is a OrgPolicyTransport instance. - if credentials or client_options.credentials_file or api_key_value: + if credentials or self._client_options.credentials_file or api_key_value: raise ValueError( "When providing a transport instance, " "provide its credentials directly." ) - if client_options.scopes: + if self._client_options.scopes: raise ValueError( "When providing a transport instance, provide its scopes " "directly." ) - self._transport = transport - else: + self._transport = cast(OrgPolicyTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or OrgPolicyClient._get_api_endpoint( + self._client_options.api_endpoint, + self._client_cert_source, + self._universe_domain, + self._use_mtls_endpoint, + ) + + if not transport_provided: import google.auth._default # type: ignore if api_key_value and hasattr( @@ -487,17 +706,17 @@ def __init__( api_key_value ) - Transport = type(self).get_transport_class(transport) + Transport = type(self).get_transport_class(cast(str, transport)) self._transport = Transport( credentials=credentials, - credentials_file=client_options.credentials_file, - host=api_endpoint, - scopes=client_options.scopes, - client_cert_source_for_mtls=client_cert_source_func, - quota_project_id=client_options.quota_project_id, + credentials_file=self._client_options.credentials_file, + host=self._api_endpoint, + scopes=self._client_options.scopes, + client_cert_source_for_mtls=self._client_cert_source, + quota_project_id=self._client_options.quota_project_id, client_info=client_info, always_use_jwt_access=True, - api_audience=client_options.api_audience, + api_audience=self._client_options.api_audience, ) def list_constraints( @@ -603,6 +822,9 @@ def sample_list_constraints(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -729,6 +951,9 @@ def sample_list_policies(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -847,6 +1072,9 @@ def sample_get_policy(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -958,6 +1186,9 @@ def sample_get_effective_policy(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1082,6 +1313,9 @@ def sample_create_policy(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1195,6 +1429,9 @@ def sample_update_policy(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1294,6 +1531,9 @@ def sample_delete_policy(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1416,6 +1656,9 @@ def sample_create_custom_constraint(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1529,6 +1772,9 @@ def sample_update_custom_constraint(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1642,6 +1888,9 @@ def sample_get_custom_constraint(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1755,6 +2004,9 @@ def sample_list_custom_constraints(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1862,6 +2114,9 @@ def sample_delete_custom_constraint(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, diff --git a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/pagers.py b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/pagers.py index a1e0f37390b0..57a2da784c34 100644 --- a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/pagers.py +++ b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/transports/__init__.py b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/transports/__init__.py index 6e7f74467de6..0639fde92fe2 100644 --- a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/transports/__init__.py +++ b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/transports/base.py b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/transports/base.py index e5efc9b759ae..055b61be8736 100644 --- a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/transports/base.py +++ b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -59,7 +59,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'orgpolicy.googleapis.com'). credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -122,6 +122,10 @@ def __init__( host += ":443" self._host = host + @property + def host(self): + return self._host + def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/transports/grpc.py b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/transports/grpc.py index 4e257986a9bf..0393ba64aa43 100644 --- a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/transports/grpc.py +++ b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -87,7 +87,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'orgpolicy.googleapis.com'). credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none diff --git a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/transports/grpc_asyncio.py b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/transports/grpc_asyncio.py index 61bcd684c86b..a518f644ed88 100644 --- a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/transports/grpc_asyncio.py +++ b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -132,7 +132,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'orgpolicy.googleapis.com'). credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none diff --git a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/transports/rest.py b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/transports/rest.py index e957b2f841e7..b5fef199dfa4 100644 --- a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/transports/rest.py +++ b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/services/org_policy/transports/rest.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -34,9 +34,9 @@ import warnings try: - OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] except AttributeError: # pragma: NO COVER - OptionalRetry = Union[retries.Retry, object] # type: ignore + OptionalRetry = Union[retries.Retry, object, None] # type: ignore from google.cloud.orgpolicy_v2.types import constraint @@ -467,7 +467,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'orgpolicy.googleapis.com'). credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -588,9 +588,7 @@ def __call__( # Jsonify the request body body = json_format.MessageToJson( - transcoded_request["body"], - including_default_value_fields=False, - use_integers_for_enums=True, + transcoded_request["body"], use_integers_for_enums=True ) uri = transcoded_request["uri"] method = transcoded_request["method"] @@ -599,7 +597,6 @@ def __call__( query_params = json.loads( json_format.MessageToJson( transcoded_request["query_params"], - including_default_value_fields=False, use_integers_for_enums=True, ) ) @@ -699,9 +696,7 @@ def __call__( # Jsonify the request body body = json_format.MessageToJson( - transcoded_request["body"], - including_default_value_fields=False, - use_integers_for_enums=True, + transcoded_request["body"], use_integers_for_enums=True ) uri = transcoded_request["uri"] method = transcoded_request["method"] @@ -710,7 +705,6 @@ def __call__( query_params = json.loads( json_format.MessageToJson( transcoded_request["query_params"], - including_default_value_fields=False, use_integers_for_enums=True, ) ) @@ -797,7 +791,6 @@ def __call__( query_params = json.loads( json_format.MessageToJson( transcoded_request["query_params"], - including_default_value_fields=False, use_integers_for_enums=True, ) ) @@ -881,7 +874,6 @@ def __call__( query_params = json.loads( json_format.MessageToJson( transcoded_request["query_params"], - including_default_value_fields=False, use_integers_for_enums=True, ) ) @@ -971,7 +963,6 @@ def __call__( query_params = json.loads( json_format.MessageToJson( transcoded_request["query_params"], - including_default_value_fields=False, use_integers_for_enums=True, ) ) @@ -1073,7 +1064,6 @@ def __call__( query_params = json.loads( json_format.MessageToJson( transcoded_request["query_params"], - including_default_value_fields=False, use_integers_for_enums=True, ) ) @@ -1172,7 +1162,6 @@ def __call__( query_params = json.loads( json_format.MessageToJson( transcoded_request["query_params"], - including_default_value_fields=False, use_integers_for_enums=True, ) ) @@ -1273,7 +1262,6 @@ def __call__( query_params = json.loads( json_format.MessageToJson( transcoded_request["query_params"], - including_default_value_fields=False, use_integers_for_enums=True, ) ) @@ -1367,7 +1355,6 @@ def __call__( query_params = json.loads( json_format.MessageToJson( transcoded_request["query_params"], - including_default_value_fields=False, use_integers_for_enums=True, ) ) @@ -1467,7 +1454,6 @@ def __call__( query_params = json.loads( json_format.MessageToJson( transcoded_request["query_params"], - including_default_value_fields=False, use_integers_for_enums=True, ) ) @@ -1562,9 +1548,7 @@ def __call__( # Jsonify the request body body = json_format.MessageToJson( - transcoded_request["body"], - including_default_value_fields=False, - use_integers_for_enums=True, + transcoded_request["body"], use_integers_for_enums=True ) uri = transcoded_request["uri"] method = transcoded_request["method"] @@ -1573,7 +1557,6 @@ def __call__( query_params = json.loads( json_format.MessageToJson( transcoded_request["query_params"], - including_default_value_fields=False, use_integers_for_enums=True, ) ) @@ -1673,9 +1656,7 @@ def __call__( # Jsonify the request body body = json_format.MessageToJson( - transcoded_request["body"], - including_default_value_fields=False, - use_integers_for_enums=True, + transcoded_request["body"], use_integers_for_enums=True ) uri = transcoded_request["uri"] method = transcoded_request["method"] @@ -1684,7 +1665,6 @@ def __call__( query_params = json.loads( json_format.MessageToJson( transcoded_request["query_params"], - including_default_value_fields=False, use_integers_for_enums=True, ) ) diff --git a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/types/__init__.py b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/types/__init__.py index 9cfdba6111bc..e7bf74eac2f6 100644 --- a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/types/__init__.py +++ b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/types/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/types/constraint.py b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/types/constraint.py index 7258e45860b6..b7fd45293a65 100644 --- a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/types/constraint.py +++ b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/types/constraint.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/types/orgpolicy.py b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/types/orgpolicy.py index 2687116a8ffe..bfe7db55a148 100644 --- a/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/types/orgpolicy.py +++ b/packages/google-cloud-org-policy/google/cloud/orgpolicy_v2/types/orgpolicy.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/pytest.ini b/packages/google-cloud-org-policy/pytest.ini index b7b37544fcb4..841d17a6ec92 100644 --- a/packages/google-cloud-org-policy/pytest.ini +++ b/packages/google-cloud-org-policy/pytest.ini @@ -8,3 +8,5 @@ filterwarnings = ignore:unclosed:ResourceWarning # Remove after support for Python 3.7 is dropped ignore:After January 1, 2024, new releases of this library will drop support for Python 3.7:DeprecationWarning + # Remove warning once https://github.com/googleapis/gapic-generator-python/issues/1939 is fixed + ignore:get_mtls_endpoint_and_cert_source is deprecated.:DeprecationWarning diff --git a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_create_custom_constraint_async.py b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_create_custom_constraint_async.py index 3a51e9ff2817..0d661924c293 100644 --- a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_create_custom_constraint_async.py +++ b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_create_custom_constraint_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_create_custom_constraint_sync.py b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_create_custom_constraint_sync.py index 3ffb32c33f84..18900bfe1cc9 100644 --- a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_create_custom_constraint_sync.py +++ b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_create_custom_constraint_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_create_policy_async.py b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_create_policy_async.py index 8d547e99142c..20497b6984d8 100644 --- a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_create_policy_async.py +++ b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_create_policy_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_create_policy_sync.py b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_create_policy_sync.py index 97dad86306e2..d469cbd6165b 100644 --- a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_create_policy_sync.py +++ b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_create_policy_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_delete_custom_constraint_async.py b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_delete_custom_constraint_async.py index 445dd3461218..647c19dcf6c6 100644 --- a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_delete_custom_constraint_async.py +++ b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_delete_custom_constraint_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_delete_custom_constraint_sync.py b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_delete_custom_constraint_sync.py index e30d1411df23..207cbf4f4648 100644 --- a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_delete_custom_constraint_sync.py +++ b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_delete_custom_constraint_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_delete_policy_async.py b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_delete_policy_async.py index 4403b1a4257b..cb78d89eefaf 100644 --- a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_delete_policy_async.py +++ b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_delete_policy_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_delete_policy_sync.py b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_delete_policy_sync.py index a2f3184f1dfd..478c7f2ed8d2 100644 --- a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_delete_policy_sync.py +++ b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_delete_policy_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_get_custom_constraint_async.py b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_get_custom_constraint_async.py index 623c1dd96e8f..97e157b854db 100644 --- a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_get_custom_constraint_async.py +++ b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_get_custom_constraint_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_get_custom_constraint_sync.py b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_get_custom_constraint_sync.py index bf1ffb82853e..d97926fef6fd 100644 --- a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_get_custom_constraint_sync.py +++ b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_get_custom_constraint_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_get_effective_policy_async.py b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_get_effective_policy_async.py index 523b55dd116e..5ab52177317e 100644 --- a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_get_effective_policy_async.py +++ b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_get_effective_policy_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_get_effective_policy_sync.py b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_get_effective_policy_sync.py index e6b6e7702940..a9b6ad476d23 100644 --- a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_get_effective_policy_sync.py +++ b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_get_effective_policy_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_get_policy_async.py b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_get_policy_async.py index a3eba961f9ef..fc7bd9b7ce95 100644 --- a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_get_policy_async.py +++ b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_get_policy_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_get_policy_sync.py b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_get_policy_sync.py index 73d474122c17..302e246f5fbf 100644 --- a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_get_policy_sync.py +++ b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_get_policy_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_list_constraints_async.py b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_list_constraints_async.py index 566ccb01a787..a0e6313fbfeb 100644 --- a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_list_constraints_async.py +++ b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_list_constraints_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_list_constraints_sync.py b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_list_constraints_sync.py index d1ffd22df088..55701d705331 100644 --- a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_list_constraints_sync.py +++ b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_list_constraints_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_list_custom_constraints_async.py b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_list_custom_constraints_async.py index 5da8e00364a7..15e060e28294 100644 --- a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_list_custom_constraints_async.py +++ b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_list_custom_constraints_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_list_custom_constraints_sync.py b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_list_custom_constraints_sync.py index ff76a0093d60..67932ee55145 100644 --- a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_list_custom_constraints_sync.py +++ b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_list_custom_constraints_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_list_policies_async.py b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_list_policies_async.py index 2eb2a7bac7e5..8bfd826386ac 100644 --- a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_list_policies_async.py +++ b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_list_policies_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_list_policies_sync.py b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_list_policies_sync.py index 9c6d1958b4b9..a63b7a390c9f 100644 --- a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_list_policies_sync.py +++ b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_list_policies_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_update_custom_constraint_async.py b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_update_custom_constraint_async.py index 856a61522b45..b74295bda613 100644 --- a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_update_custom_constraint_async.py +++ b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_update_custom_constraint_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_update_custom_constraint_sync.py b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_update_custom_constraint_sync.py index baf9603a2bcd..218465ad6724 100644 --- a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_update_custom_constraint_sync.py +++ b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_update_custom_constraint_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_update_policy_async.py b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_update_policy_async.py index eac8025fb78c..686ca097fb9f 100644 --- a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_update_policy_async.py +++ b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_update_policy_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_update_policy_sync.py b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_update_policy_sync.py index 41613619be6b..077629d0258d 100644 --- a/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_update_policy_sync.py +++ b/packages/google-cloud-org-policy/samples/generated_samples/orgpolicy_v2_generated_org_policy_update_policy_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/samples/generated_samples/snippet_metadata_google.cloud.orgpolicy.v2.json b/packages/google-cloud-org-policy/samples/generated_samples/snippet_metadata_google.cloud.orgpolicy.v2.json index 831c2332921d..b5d00f81e259 100644 --- a/packages/google-cloud-org-policy/samples/generated_samples/snippet_metadata_google.cloud.orgpolicy.v2.json +++ b/packages/google-cloud-org-policy/samples/generated_samples/snippet_metadata_google.cloud.orgpolicy.v2.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-org-policy", - "version": "1.10.0" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-org-policy/scripts/fixup_orgpolicy_v2_keywords.py b/packages/google-cloud-org-policy/scripts/fixup_orgpolicy_v2_keywords.py index d3f91087bc34..767011cbab61 100644 --- a/packages/google-cloud-org-policy/scripts/fixup_orgpolicy_v2_keywords.py +++ b/packages/google-cloud-org-policy/scripts/fixup_orgpolicy_v2_keywords.py @@ -1,6 +1,6 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/setup.py b/packages/google-cloud-org-policy/setup.py index 5baf7029417a..1e3017d3783f 100644 --- a/packages/google-cloud-org-policy/setup.py +++ b/packages/google-cloud-org-policy/setup.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -39,7 +39,10 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.0, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 1.34.1, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + # Exclude incompatible versions of `google-auth` + # See https://github.com/googleapis/google-cloud-python/issues/12364 + "google-auth >= 2.14.1, <3.0.0dev,!=2.24.0,!=2.25.0", "proto-plus >= 1.22.3, <2.0.0dev", "protobuf>=3.19.5,<5.0.0dev,!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", ] diff --git a/packages/google-cloud-org-policy/testing/constraints-3.7.txt b/packages/google-cloud-org-policy/testing/constraints-3.7.txt index 185f7d366c2f..b8a550c73855 100644 --- a/packages/google-cloud-org-policy/testing/constraints-3.7.txt +++ b/packages/google-cloud-org-policy/testing/constraints-3.7.txt @@ -4,6 +4,7 @@ # Pin the version to the lower bound. # e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0dev", # Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.0 +google-api-core==1.34.1 +google-auth==2.14.1 proto-plus==1.22.3 protobuf==3.19.5 diff --git a/packages/google-cloud-org-policy/tests/unit/__init__.py b/packages/google-cloud-org-policy/tests/unit/__init__.py index 89a37dc92c5a..8f6cf068242c 100644 --- a/packages/google-cloud-org-policy/tests/unit/__init__.py +++ b/packages/google-cloud-org-policy/tests/unit/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/tests/unit/gapic/__init__.py b/packages/google-cloud-org-policy/tests/unit/gapic/__init__.py index 89a37dc92c5a..8f6cf068242c 100644 --- a/packages/google-cloud-org-policy/tests/unit/gapic/__init__.py +++ b/packages/google-cloud-org-policy/tests/unit/gapic/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/tests/unit/gapic/orgpolicy_v2/__init__.py b/packages/google-cloud-org-policy/tests/unit/gapic/orgpolicy_v2/__init__.py index 89a37dc92c5a..8f6cf068242c 100644 --- a/packages/google-cloud-org-policy/tests/unit/gapic/orgpolicy_v2/__init__.py +++ b/packages/google-cloud-org-policy/tests/unit/gapic/orgpolicy_v2/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-org-policy/tests/unit/gapic/orgpolicy_v2/test_org_policy.py b/packages/google-cloud-org-policy/tests/unit/gapic/orgpolicy_v2/test_org_policy.py index f021bc5d36dd..70220da3b1c4 100644 --- a/packages/google-cloud-org-policy/tests/unit/gapic/orgpolicy_v2/test_org_policy.py +++ b/packages/google-cloud-org-policy/tests/unit/gapic/orgpolicy_v2/test_org_policy.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ import json import math import pytest +from google.api_core import api_core_version from proto.marshal.rules.dates import DurationRule, TimestampRule from proto.marshal.rules import wrappers from requests import Response @@ -72,6 +73,17 @@ def modify_default_endpoint(client): ) +# If default endpoint template is localhost, then default mtls endpoint will be the same. +# This method modifies the default endpoint template so the client can produce a different +# mtls endpoint for endpoint testing purposes. +def modify_default_endpoint_template(client): + return ( + "test.{UNIVERSE_DOMAIN}" + if ("localhost" in client._DEFAULT_ENDPOINT_TEMPLATE) + else client._DEFAULT_ENDPOINT_TEMPLATE + ) + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -96,6 +108,254 @@ def test__get_default_mtls_endpoint(): assert OrgPolicyClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert OrgPolicyClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert OrgPolicyClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert OrgPolicyClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + OrgPolicyClient._read_environment_variables() + assert ( + str(excinfo.value) + == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + assert OrgPolicyClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert OrgPolicyClient._read_environment_variables() == (False, "always", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert OrgPolicyClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + OrgPolicyClient._read_environment_variables() + assert ( + str(excinfo.value) + == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + with mock.patch.dict(os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "foo.com"}): + assert OrgPolicyClient._read_environment_variables() == ( + False, + "auto", + "foo.com", + ) + + +def test__get_client_cert_source(): + mock_provided_cert_source = mock.Mock() + mock_default_cert_source = mock.Mock() + + assert OrgPolicyClient._get_client_cert_source(None, False) is None + assert ( + OrgPolicyClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + OrgPolicyClient._get_client_cert_source(mock_provided_cert_source, True) + == mock_provided_cert_source + ) + + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", return_value=True + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_default_cert_source, + ): + assert ( + OrgPolicyClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + OrgPolicyClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + OrgPolicyClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(OrgPolicyClient), +) +@mock.patch.object( + OrgPolicyAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(OrgPolicyAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = OrgPolicyClient._DEFAULT_UNIVERSE + default_endpoint = OrgPolicyClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = OrgPolicyClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + OrgPolicyClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + OrgPolicyClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == OrgPolicyClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + OrgPolicyClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + OrgPolicyClient._get_api_endpoint(None, None, default_universe, "always") + == OrgPolicyClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + OrgPolicyClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == OrgPolicyClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + OrgPolicyClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + OrgPolicyClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + OrgPolicyClient._get_api_endpoint( + None, mock_client_cert_source, mock_universe, "auto" + ) + assert ( + str(excinfo.value) + == "mTLS is not supported in any universe other than googleapis.com." + ) + + +def test__get_universe_domain(): + client_universe_domain = "foo.com" + universe_domain_env = "bar.com" + + assert ( + OrgPolicyClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + OrgPolicyClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + OrgPolicyClient._get_universe_domain(None, None) + == OrgPolicyClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + OrgPolicyClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (OrgPolicyClient, transports.OrgPolicyGrpcTransport, "grpc"), + (OrgPolicyClient, transports.OrgPolicyRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=ga_credentials.AnonymousCredentials()) + ) + assert client._validate_universe_domain() == True + + # Test the case when universe is already validated. + assert client._validate_universe_domain() == True + + if transport_name == "grpc": + # Test the case where credentials are provided by the + # `local_channel_credentials`. The default universes in both match. + channel = grpc.secure_channel( + "http://localhost/", grpc.local_channel_credentials() + ) + client = client_class(transport=transport_class(channel=channel)) + assert client._validate_universe_domain() == True + + # Test the case where credentials do not exist: e.g. a transport is provided + # with no credentials. Validation should still succeed because there is no + # mismatch with non-existent credentials. + channel = grpc.secure_channel( + "http://localhost/", grpc.local_channel_credentials() + ) + transport = transport_class(channel=channel) + transport._credentials = None + client = client_class(transport=transport) + assert client._validate_universe_domain() == True + + # TODO: This is needed to cater for older versions of google-auth + # Make this test unconditional once the minimum supported version of + # google-auth becomes 2.23.0 or higher. + google_auth_major, google_auth_minor = [ + int(part) for part in google.auth.__version__.split(".")[0:2] + ] + if google_auth_major > 2 or (google_auth_major == 2 and google_auth_minor >= 23): + credentials = ga_credentials.AnonymousCredentials() + credentials._universe_domain = "foo.com" + # Test the case when there is a universe mismatch from the credentials. + client = client_class(transport=transport_class(credentials=credentials)) + with pytest.raises(ValueError) as excinfo: + client._validate_universe_domain() + assert ( + str(excinfo.value) + == "The configured universe domain (googleapis.com) does not match the universe domain found in the credentials (foo.com). If you haven't configured the universe domain explicitly, `googleapis.com` is the default." + ) + + # Test the case when there is a universe mismatch from the client. + # + # TODO: Make this test unconditional once the minimum supported version of + # google-api-core becomes 2.15.0 or higher. + api_core_major, api_core_minor = [ + int(part) for part in api_core_version.__version__.split(".")[0:2] + ] + if api_core_major > 2 or (api_core_major == 2 and api_core_minor >= 15): + client = client_class( + client_options={"universe_domain": "bar.com"}, + transport=transport_class( + credentials=ga_credentials.AnonymousCredentials(), + ), + ) + with pytest.raises(ValueError) as excinfo: + client._validate_universe_domain() + assert ( + str(excinfo.value) + == "The configured universe domain (bar.com) does not match the universe domain found in the credentials (googleapis.com). If you haven't configured the universe domain explicitly, `googleapis.com` is the default." + ) + + # Test that ValueError is raised if universe_domain is provided via client options and credentials is None + with pytest.raises(ValueError): + client._compare_universes("foo.bar", None) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -206,12 +466,14 @@ def test_org_policy_client_get_transport_class(): ], ) @mock.patch.object( - OrgPolicyClient, "DEFAULT_ENDPOINT", modify_default_endpoint(OrgPolicyClient) + OrgPolicyClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(OrgPolicyClient), ) @mock.patch.object( OrgPolicyAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(OrgPolicyAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(OrgPolicyAsyncClient), ) def test_org_policy_client_client_options( client_class, transport_class, transport_name @@ -253,7 +515,9 @@ def test_org_policy_client_client_options( patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_ENDPOINT, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ), scopes=None, client_cert_source_for_mtls=None, quota_project_id=None, @@ -283,15 +547,23 @@ def test_org_policy_client_client_options( # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): - with pytest.raises(MutualTLSChannelError): + with pytest.raises(MutualTLSChannelError) as excinfo: client = client_class(transport=transport_name) + assert ( + str(excinfo.value) + == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): - with pytest.raises(ValueError): + with pytest.raises(ValueError) as excinfo: client = client_class(transport=transport_name) + assert ( + str(excinfo.value) + == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") @@ -301,7 +573,9 @@ def test_org_policy_client_client_options( patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_ENDPOINT, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ), scopes=None, client_cert_source_for_mtls=None, quota_project_id="octopus", @@ -319,7 +593,9 @@ def test_org_policy_client_client_options( patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_ENDPOINT, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ), scopes=None, client_cert_source_for_mtls=None, quota_project_id=None, @@ -351,12 +627,14 @@ def test_org_policy_client_client_options( ], ) @mock.patch.object( - OrgPolicyClient, "DEFAULT_ENDPOINT", modify_default_endpoint(OrgPolicyClient) + OrgPolicyClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(OrgPolicyClient), ) @mock.patch.object( OrgPolicyAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(OrgPolicyAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(OrgPolicyAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_org_policy_client_mtls_env_auto( @@ -379,7 +657,9 @@ def test_org_policy_client_mtls_env_auto( if use_client_cert_env == "false": expected_client_cert_source = None - expected_host = client.DEFAULT_ENDPOINT + expected_host = client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ) else: expected_client_cert_source = client_cert_source_callback expected_host = client.DEFAULT_MTLS_ENDPOINT @@ -411,7 +691,9 @@ def test_org_policy_client_mtls_env_auto( return_value=client_cert_source_callback, ): if use_client_cert_env == "false": - expected_host = client.DEFAULT_ENDPOINT + expected_host = client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ) expected_client_cert_source = None else: expected_host = client.DEFAULT_MTLS_ENDPOINT @@ -445,7 +727,9 @@ def test_org_policy_client_mtls_env_auto( patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_ENDPOINT, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ), scopes=None, client_cert_source_for_mtls=None, quota_project_id=None, @@ -531,6 +815,113 @@ def test_org_policy_client_get_mtls_endpoint_and_cert_source(client_class): assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT assert cert_source == mock_client_cert_source + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has + # unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + client_class.get_mtls_endpoint_and_cert_source() + + assert ( + str(excinfo.value) + == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + client_class.get_mtls_endpoint_and_cert_source() + + assert ( + str(excinfo.value) + == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + + +@pytest.mark.parametrize("client_class", [OrgPolicyClient, OrgPolicyAsyncClient]) +@mock.patch.object( + OrgPolicyClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(OrgPolicyClient), +) +@mock.patch.object( + OrgPolicyAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(OrgPolicyAsyncClient), +) +def test_org_policy_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = OrgPolicyClient._DEFAULT_UNIVERSE + default_endpoint = OrgPolicyClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = OrgPolicyClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + # If ClientOptions.api_endpoint is set and GOOGLE_API_USE_CLIENT_CERTIFICATE="true", + # use ClientOptions.api_endpoint as the api endpoint regardless. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" + ): + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=api_override + ) + client = client_class( + client_options=options, + credentials=ga_credentials.AnonymousCredentials(), + ) + assert client.api_endpoint == api_override + + # If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never", + # use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + client = client_class(credentials=ga_credentials.AnonymousCredentials()) + assert client.api_endpoint == default_endpoint + + # If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="always", + # use the DEFAULT_MTLS_ENDPOINT as the api endpoint. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + client = client_class(credentials=ga_credentials.AnonymousCredentials()) + assert client.api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + + # If ClientOptions.api_endpoint is not set, GOOGLE_API_USE_MTLS_ENDPOINT="auto" (default), + # GOOGLE_API_USE_CLIENT_CERTIFICATE="false" (default), default cert source doesn't exist, + # and ClientOptions.universe_domain="bar.com", + # use the _DEFAULT_ENDPOINT_TEMPLATE populated with universe domain as the api endpoint. + options = client_options.ClientOptions() + universe_exists = hasattr(options, "universe_domain") + if universe_exists: + options = client_options.ClientOptions(universe_domain=mock_universe) + client = client_class( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + else: + client = client_class( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + assert client.api_endpoint == ( + mock_endpoint if universe_exists else default_endpoint + ) + assert client.universe_domain == ( + mock_universe if universe_exists else default_universe + ) + + # If ClientOptions does not have a universe domain attribute and GOOGLE_API_USE_MTLS_ENDPOINT="never", + # use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint. + options = client_options.ClientOptions() + if hasattr(options, "universe_domain"): + delattr(options, "universe_domain") + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + client = client_class( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -557,7 +948,9 @@ def test_org_policy_client_client_options_scopes( patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_ENDPOINT, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ), scopes=["1", "2"], client_cert_source_for_mtls=None, quota_project_id=None, @@ -592,7 +985,9 @@ def test_org_policy_client_client_options_credentials_file( patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", - host=client.DEFAULT_ENDPOINT, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ), scopes=None, client_cert_source_for_mtls=None, quota_project_id=None, @@ -645,7 +1040,9 @@ def test_org_policy_client_create_channel_credentials_file( patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", - host=client.DEFAULT_ENDPOINT, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ), scopes=None, client_cert_source_for_mtls=None, quota_project_id=None, @@ -917,7 +1314,7 @@ async def test_list_constraints_flattened_error_async(): def test_list_constraints_pager(transport_name: str = "grpc"): client = OrgPolicyClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials(), transport=transport_name, ) @@ -967,7 +1364,7 @@ def test_list_constraints_pager(transport_name: str = "grpc"): def test_list_constraints_pages(transport_name: str = "grpc"): client = OrgPolicyClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials(), transport=transport_name, ) @@ -1009,7 +1406,7 @@ def test_list_constraints_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_constraints_async_pager(): client = OrgPolicyAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1059,7 +1456,7 @@ async def test_list_constraints_async_pager(): @pytest.mark.asyncio async def test_list_constraints_async_pages(): client = OrgPolicyAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1339,7 +1736,7 @@ async def test_list_policies_flattened_error_async(): def test_list_policies_pager(transport_name: str = "grpc"): client = OrgPolicyClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials(), transport=transport_name, ) @@ -1389,7 +1786,7 @@ def test_list_policies_pager(transport_name: str = "grpc"): def test_list_policies_pages(transport_name: str = "grpc"): client = OrgPolicyClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials(), transport=transport_name, ) @@ -1431,7 +1828,7 @@ def test_list_policies_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_policies_async_pager(): client = OrgPolicyAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1481,7 +1878,7 @@ async def test_list_policies_async_pager(): @pytest.mark.asyncio async def test_list_policies_async_pages(): client = OrgPolicyAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3769,7 +4166,7 @@ async def test_list_custom_constraints_flattened_error_async(): def test_list_custom_constraints_pager(transport_name: str = "grpc"): client = OrgPolicyClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials(), transport=transport_name, ) @@ -3821,7 +4218,7 @@ def test_list_custom_constraints_pager(transport_name: str = "grpc"): def test_list_custom_constraints_pages(transport_name: str = "grpc"): client = OrgPolicyClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials(), transport=transport_name, ) @@ -3865,7 +4262,7 @@ def test_list_custom_constraints_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_custom_constraints_async_pager(): client = OrgPolicyAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3917,7 +4314,7 @@ async def test_list_custom_constraints_async_pager(): @pytest.mark.asyncio async def test_list_custom_constraints_async_pages(): client = OrgPolicyAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4250,11 +4647,7 @@ def test_list_constraints_rest_required_fields( request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( - json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False, - ) + json_format.MessageToJson(pb_request, use_integers_for_enums=False) ) # verify fields with default values are dropped @@ -4585,11 +4978,7 @@ def test_list_policies_rest_required_fields(request_type=orgpolicy.ListPoliciesR request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( - json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False, - ) + json_format.MessageToJson(pb_request, use_integers_for_enums=False) ) # verify fields with default values are dropped @@ -4920,11 +5309,7 @@ def test_get_policy_rest_required_fields(request_type=orgpolicy.GetPolicyRequest request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( - json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False, - ) + json_format.MessageToJson(pb_request, use_integers_for_enums=False) ) # verify fields with default values are dropped @@ -5185,11 +5570,7 @@ def test_get_effective_policy_rest_required_fields( request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( - json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False, - ) + json_format.MessageToJson(pb_request, use_integers_for_enums=False) ) # verify fields with default values are dropped @@ -5554,11 +5935,7 @@ def test_create_policy_rest_required_fields(request_type=orgpolicy.CreatePolicyR request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( - json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False, - ) + json_format.MessageToJson(pb_request, use_integers_for_enums=False) ) # verify fields with default values are dropped @@ -5929,11 +6306,7 @@ def test_update_policy_rest_required_fields(request_type=orgpolicy.UpdatePolicyR request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( - json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False, - ) + json_format.MessageToJson(pb_request, use_integers_for_enums=False) ) # verify fields with default values are dropped @@ -6185,11 +6558,7 @@ def test_delete_policy_rest_required_fields(request_type=orgpolicy.DeletePolicyR request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( - json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False, - ) + json_format.MessageToJson(pb_request, use_integers_for_enums=False) ) # verify fields with default values are dropped @@ -6530,11 +6899,7 @@ def test_create_custom_constraint_rest_required_fields( request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( - json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False, - ) + json_format.MessageToJson(pb_request, use_integers_for_enums=False) ) # verify fields with default values are dropped @@ -6901,11 +7266,7 @@ def test_update_custom_constraint_rest_required_fields( request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( - json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False, - ) + json_format.MessageToJson(pb_request, use_integers_for_enums=False) ) # verify fields with default values are dropped @@ -7185,11 +7546,7 @@ def test_get_custom_constraint_rest_required_fields( request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( - json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False, - ) + json_format.MessageToJson(pb_request, use_integers_for_enums=False) ) # verify fields with default values are dropped @@ -7453,11 +7810,7 @@ def test_list_custom_constraints_rest_required_fields( request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( - json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False, - ) + json_format.MessageToJson(pb_request, use_integers_for_enums=False) ) # verify fields with default values are dropped @@ -7788,11 +8141,7 @@ def test_delete_custom_constraint_rest_required_fields( request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( - json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False, - ) + json_format.MessageToJson(pb_request, use_integers_for_enums=False) ) # verify fields with default values are dropped @@ -8027,7 +8376,7 @@ def test_credentials_transport_error(): ) # It is an error to provide an api_key and a credential. - options = mock.Mock() + options = client_options.ClientOptions() options.api_key = "api_key" with pytest.raises(ValueError): client = OrgPolicyClient( @@ -8822,7 +9171,9 @@ def test_api_key_credentials(client_class, transport_class): patched.assert_called_once_with( credentials=mock_cred, credentials_file=None, - host=client.DEFAULT_ENDPOINT, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ), scopes=None, client_cert_source_for_mtls=None, quota_project_id=None,